narwhal-mongodb icon indicating copy to clipboard operation
narwhal-mongodb copied to clipboard

Problem querying arrays

Open oravecz opened this issue 15 years ago • 1 comments

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);

oravecz avatar Jun 15 '10 18:06 oravecz

Thanks for filing it oravecz, I will be looking into it as soon as possible.

sergi avatar Jun 15 '10 21:06 sergi