DBRef is not defined 求解
发布于 11 年前 作者 xiao2013 5049 次浏览 最后一次编辑是 8 年前

var comment = { postId: this.postId, name: this.name, comment: this.comment, commentId:this.commentId, upid:new DBRef(‘users’,objectId(uid)) }; 我是想把comments文档和users文档做关联 但是执行到upid:new DBRef(‘users’,objectId(uid)) 时出错,提示 DBRef is not defined 用DBRef还需要有什么引用吗 求解

5 回复
var mongo = require('mongodb');
// 其它代码
var comment = {
postId: this.postId,
name: this.name,
comment: this.comment,
commentId:this.commentId,
// DbRef前加上你定义的mongodb实例对象
upid:new mongo.DBRef('users',objectId(uid))
};

恩 谢谢 是这样的 还有问题 想请教一下 就是这个DBRef 我要怎么用呢 它能很方面的获得users文档里面的东西吗 ? 希望能说的详细一些 有示例代码更好

@xiao2013 沉了。。。

  1. 凝练出关键词组合,利用Google搜索引擎,自己去找资料,找答案。
  2. 教程代替不了官方文档,仔细看看。
  3. 写一个简单的程序,能够重现你的问题。提交到如github.com上,大家再帮忙看看。

恩,非常谢谢

回到顶部