Having a collection of logbooks with logs
{
type:'logbook',
name:'my book',
userRef:2,
cdate: ....,
logs: [
{
color: 'red',
weight: 200,
cdate: ...,
foo: 'bar'
}开发者_StackOverflow,
{
color: 'blue',
weight: 100,
cdate: ...,
foo: 'bar'
},
{
color: 'green',
weight: 240,
cdate: ...,
foo: 'bar'
}
]
How can I get distinct color for a given logbook item ?
I tried
db.dgacavionlogbook.distinct("logs.aeronef.type", {name: 'DGAC'})
http://www.mongodb.org/display/DOCS/Aggregation
With no success :/
Aggregation works across documents. If you want to aggregate within a document you need to do it client-side or use Map/Reduce (which is kinda silly); I'd suggest doing it in the client.
精彩评论