narwhal-mongodb
narwhal-mongodb copied to clipboard
Problem querying arrays
I'm noticing that a JS object with an embedded array, var o = { tags: ['A', 'B', 'C'] }
ends up in MongoDB as such (according to Mongo Shell):
{ "_id": ObjectId("..."), "tags": { "0": "A", "1": "B", "2":"C"} }
I think it is your call to: new Packages.com.mongodb.BasicDBObject(obj)
This is converting the array to a map. Is this the behavior you are expecting?
If I do something similar in Java, the Mongo Shell shows me the array. Mongo m = new Mongo( "localhost" , 27017 ); DB db = m.getDB( "mydb" ); DBCollection coll = db.getCollection("blog");
String[] tags = {"first", "second", "third"};
Map map = new HashMap();
map.put("author", "me");
map.put("tags", tags);
BasicDBObject post = new BasicDBObject("post", map);
coll.insert(post);
Thanks for filing it oravecz, I will be looking into it as soon as possible.