发布于 2015-09-14 15:11:52 | 196 次阅读 | 评论: 0 | 来源: 网络整理
The documentation generally gives examples in JavaScript, use this chart to convert those examples to any language.
| JavaScript | Python | PHP | Ruby | Java | C++ | C# | Perl | 
|---|---|---|---|---|---|---|---|
[ ]
 | 
[]
 | 
array()
 | 
[]
 | 
BasicDBList
 | 
BSONObj
or bson::bo
 | 
BsonArray
 | 
[ ]
 | 
{}
 | 
{}
 | 
new stdClass
 | 
{}
 | 
BasicDBObject
 | 
BSONObj
 | 
BsonDocument
 | 
{}
 | 
{ x : 1 }
 | 
{"x": 1}
 | 
array('x' => 1)
 | 
{'x' => 1}
 | 
BasicDBObjectBuilder.start().add("x", 1).get()
 | 
BSONObjBuilder().append("x", 1).obj();
BSON( "x" << 1 )
 | 
new BsonDocument("x", 1)
 | 
{ x : 1 }
 | 
connect("www.example.net")
 | 
Connection("www.example.net")
 | 
new Mongo("www.example.net")
 | 
Connection.new("www.example.net")
 | 
new Mongo("www.example.net", "dbname")
 | 
mongo::DBClientConnection conn;
conn.connect("www.example.net");
 | 
var server = MongoServer.Create("mongodb://www.example.net");
 | 
MongoDB::Connection->new(host => 'www.example.net')
 | 
cursor.next()
 | 
cursor.next()
 | 
$cursor->getNext()
 | 
cursor.next_document()
 | 
cursor.next()
 | 
cursor.next()
 | 
foreach (var document in cursor)
 | 
$cursor->next()
 | 
cursor.hasNext()
 | 
Does not exist | $cursor->hasNext()
 | 
cursor.has_next?
 | 
cursor.hasNext()
 | 
cursor.more()
 | 
$cursor->has_next()
 | 
|
collection.findOne()
 | 
collection.find_one()
 | 
$collection->findOne()
 | 
collection.find_one()
 | 
collection.findOne()
 | 
connection.findOne(namespace, query)
 | 
collection.FindOne()
 | 
$collection->find_one()
 | 
db.eval()
 | 
db.eval()
 | 
$db->execute()
 | 
db.eval()
 | 
db.doEval()
 | 
connection.eval()
 | 
db.Eval(js)
 | 
$db->eval()
 |