开发者

Mongo distinct and embedded list (Query)

开发者 https://www.devze.com 2023-01-26 21:09 出处:网络
Having a collection of logbooks with logs { type:\'logbook\', name:\'my book\', userRef:2, cdate: ...., logs: [

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号