在猫鼬中指定架构 [英] Specify schema in mongoose

查看:89
本文介绍了在猫鼬中指定架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道定义此架构的最佳方法是什么

I was wondering what the best way to define this schema is:

Newsitem只能具有1个用户ID和1个任务ID. 一个任务可以属于许多新站点. 一个用户可以属于许多新站点

Newsitem can only have 1 userID and 1 task ID. A Task can belong to many newsitems. A user can belong to many newsitems

我已经搜索了示例,但我想说它们不是很多示例.我该如何用猫鼬做这件事? mongodb?我想说Newsitem的用户和Newsitem的任务都是一对多的关系.

I've searched for examples, but I'd say they are not a lot of examples. How can I do this with mongoose & mongodb ? I'd say that both User to newsitem and Task to Newsitem are one to many relations.

推荐答案

在Mongodb中,您可以引用架构中的一个集合,这样当您在newsitem中找到()文档时,猫鼬会在用户和任务中执行一次find(),因此,返回newsitem文档的过程,它将连同用户和任务一起返回newsitem.

In Mongodb you can reference a collection within a schema so when you find() a document in newsitem mongoose does a find() in user and task, so instead of returning the newsitem document it returns the newsitem with the user and the task.

猫鼬人口

这篇关于在猫鼬中指定架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆