I know that this question has been raised many times ago and Mongo does not have "many" connections, but I So far, I failed to make the connection between the two schemas. Here's what I have:
User model (user.js)
var userSchema = mongoose.Schema ({post: {_id: {type: Schema.Type object) Id, ref: 'post'}, title: {type: string, ref: 'post'}}, facebook: {id: string, token: string, email: string, name: string}});
and post schema (post.js)
var meetingsSharma = Mongoose Sema ({title: string, description: string, _owner: {type: schema} type id, referee: 'user'}, owner name: {type: string, ref: 'user'}, created_t: {type: date , Default: Date.Now},});
I use the schema population and it works right with the post: Owner of each one, however, it does not work well with users. I want to be able to recover the list of users who belong to those posts. In Routes Js I define an API call to the database
app .get ('/ API / user', function (rick, ridge)) {user.find (function (mistake, user) { If (mistake) res.send (err) res.json (user);}) populate ('posts._id', 'posts.title');});
But, in the shell and (not surprisingly) clientide user.posts in the blank array. How can I tie these two models properly?
Just a wild guess
- You are
user.find all users. - Then you return them all.
- Then you pop the post id and the title, which already too late because you have already sent users.
See examples of population.
In addition to this, I hope that .posts
property to be an array, not just the aircraft article comment
property view.
No comments:
Post a Comment