Skip to content

Problem querying arrays #1

@oravecz

Description

@oravecz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions