-
Notifications
You must be signed in to change notification settings - Fork 16
Problem querying arrays #1
Copy link
Copy link
Open
Description
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);
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels