简体   繁体   中英

How to select documents on a collection with unique field in mongodb and meteor?

How to select documents in a collection with a unique field in MongoDB?

I have this document schema:

{
  _id: someid,
  createdAt: new Date(),
  message: somemessage,
  eadd: eadd
}

I would like to get recent messages with unique email address. So the output will be recent messages per email address.

I don't know how to use Group by - can I use it here?

to get aggregation in Meteor, you'll have add a package. eg meteorhacks:aggregate

cf https://themeteorchef.com/tutorials/aggregations-in-mongodb

You will have to use the mongo aggregate function

db.messages.aggregate(
[
  {
     $group : {
       _id : "$eadd"}
  }
]);

Just include the fields you want to show

You can try http://grapher.cultofcoders.com/ package. It will allow you to create relationships between your mongo collections. You will use links to create them and you can filter your requests to the database, pass parameters and more.

To install it

meteor add cultofcoders:grapher

Documentation can be found here: http://grapher.cultofcoders.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM