Flyingbeaver
Flyingbeaver

Reputation: 375

Strange results mongodb

Could someone explain me why do I have the following result with the following data in my db :

Data in the DB :

{
  "_id": { "$oid" : "4E4BDA5A068E2C5B0E450100" },
  "name" : "john",
  "object" : {
    "A":"1",
    "B":"2"
  },
  "array" : [
    {"A":"1"},
    {"B":"2"}
  ]
}

Query :

db.collection.find( { name : "john" } );

Result :

{ "_id" : ObjectId("4e4bda5a068e2c5b0e450100"), "name" : "john", "object" : { "A" : "1", "B" : "2" }, "array" : [ { "B" : "2" } ] }

Where is my array A:1 ??? Thx for your help.

Mongo 2.0.1

Upvotes: 1

Views: 59

Answers (1)

Tyler Brock
Tyler Brock

Reputation: 30136

Something in your syntax must be wrong.

Inserting your doc:

db.free4297.insert({
  "_id": { _id: ObjectId("4E4BDA5A068E2C5B0E450100") },
  "name" : "john",
  "object" : {
    "A":"1",
    "B":"2"
  },
  "array" : [
    {"A":"1"},
    {"B":"2"}
  ]
})

Then:

db.free4297.findOne( { name: "john" } )

{
    "_id" : {
        "_id" : ObjectId("4e4bda5a068e2c5b0e450100")
    },
    "name" : "john",
    "object" : {
        "A" : "1",
        "B" : "2"
    },
    "array" : [
        {
            "A" : "1"
        },
        {
            "B" : "2"
        }
    ]
}

Upvotes: 2

Related Questions