The wiki generally gives examples in JavaScript, so this chart can be used 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.connnect("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() |
* |
$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() |
* does not exist in that language
PLEASE POST QUESTIONS IN THE FORUMS: http://groups.google.com/group/mongodb-user. Post tips and clarifications here.
blog comments powered by Disqus