How to post two collections from mongodb

Hi there
I have two collection

Users

{ 
    "_id" : ObjectId("57ee0b8f7c705870a0196ee3"), 
    "username" : "John", 
    "email" : "a3_prince@naver.com", 
    "password" : "qus900!!"
}

and Posts

{ 
    "_id" : ObjectId("57ee2b557c705870a0196ef6"), 
    "title" : "How to get embedded object in mongodB shell", 
    "contents" : "You can connect like so:\n\nvar database = new ", 
    "regId" : "9TKD5mo6qM5jFzX3S", 
    "createdAt" : "2016-09-30-09-11", 
    "groupId" : "5onHGJKyJvq63Lt3J", 
    "viewCount" : NumberInt(100), 
  
}

and I wanna post two collection

posts.title, users.username, viewCount

So I did publish like this

if (Meteor.isServer) {
  Meteor.publish('posts', function(groupId) {
    var post_regIds, user_ids;
    post_regIds = posts.find({
      groupId: groupId
    }, {
      fields: {
        regId: 1
      }
    });
    user_ids = post_regIds.map(function(p) {
      return p.regId;
    });
    return [
      posts.find({
        groupId: groupId
      }), Meteor.users.find({
        _id: {
          $in: user_ids
        }
      })
    ];
  });
}

anyway How can I post two more collections?

Someone help me ~

try these packages

https://github.com/cult-of-coders/grapher

https://github.com/englue/meteor-publish-composite

https://github.com/peerlibrary/meteor-reactive-publish

https://github.com/maximummeteor/server-transform
1 Like

Thank you
Have you ever try concat function??

you can publish multiple cursors on server.

yes sometimes we use concat in meteor call or publish