Asked this over on StackOverflow but everyone there was as puzzled as I was. Wanted to see if anyone here might know the answer!
Using MeteorJS, I have a MongoDB collection where each document has an address field that is an array of objects. Here’s how it looks in the db:
{
"_id" : "eEzHuNCHPPGNLo2mp",
"addresses" : [
{
"type" : "Dropoff",
"street" : "123 MAIN ST",
"street2" : "",
"city" : "ANYTOWN",
"state" : "ST",
"zip" : "12345-6789",
"country" : "US",
"loc" : {
"type" : "Point",
"coordinates" : [
-100.100100,
30.303030
]
}
}
]
}
When I go to the command line and try db.docs.find({_id: 'eEzHuNCHPPGNLo2mp' },{ 'addresses': 1 });
I get that exact output.
Here’s how I would find the same document via Meteor’s Mongo implementation:
var docs = Docs.find(
{ '_id': 'eEzHuNCHPPGNLo2mp' },
{ fields: { 'addresses': 1 } }
).fetch();
When I do that though, the document comes back as:
[{
type: 'Dropoff',
street: '123 MAIN ST',
city: 'ANYTOWN',
state: 'ST',
zip: '12345-6789',
country: 'US'
}]
Both the street2
and loc
properties have been dropped.
Even if I ask for each property specifically, it will not return them.
I’ve tried find()
and findOne()
with the same results.
I’m doing this on the server, not the client, so there’s no issue with published data.
To make this more weird, I tried it without the projection and while I got back every field in the collection, the addresses array still has those fields cut off.
Finally, this happens with all items, not just a single item.
Any ideas?