【发布时间】:2016-05-03 00:17:13
【问题描述】:
上下文
所以我们已经从 Parse.com 迁移到托管的 MongoDB 数据库。现在我必须编写一个脚本来直接查询我们的数据库(不使用 Parse)。
我正在使用 nodejs / mongoose 并且能够检索这些文档。
问题
到目前为止,这是我的架构:
var StorySchema = new mongoose.Schema({
_id: String,
genre: String
});
var ActivitySchema = new mongoose.Schema({
_id: String,
action: String,
_p_story: String /* Also tried: { type: mongoose.Schema.Types.ObjectId, ref: 'Story' } and { type: String, ref: 'Story' }*/,
});
我想编写一个查询来获取这些文档以及相关的 Story(存储为指针)。
Activity
.find({
action: 'read',
})
.exec(function(error, activities) {
activities.forEach(function(activity) {
// I would like to use activity._p_story or whatever the mean to access the story here
});
});
问题
鉴于_p_story 字段在对象ID 之前包含Story$,有没有办法让获取的活动填充他们的故事?
谢谢!
【问题讨论】:
-
只是评论,但您可以运行自己的解析服务器,而不是重写所有查询。 github.com/ParsePlatform/parse-server。示例应用程序使其变得简单,“解析服务器示例应用程序”部分。
-
我一直在寻求做同样的事情来绕过一些限制。你能做到吗?
标签: node.js parse-platform mongoose