publishCreate接受什么类型的Object?

时间:2015-03-08 16:21:54

标签: mongodb socket.io sails.js sails-mongo

当我使用时:

User.publishCreate(user.id);

我的服务器记录:

error: Invalid usage of publishCreate() :: Values must have an `id`, instead got :: '54fc5ebf4da88b7260445f7d'

我的数据存储在创建ObjectID的MongoDB中。如果我使用user.id,它应该传递ObjectID.toString(),但这不是我的publishCreate方法所采用的。

2 个答案:

答案 0 :(得分:1)

不要使用" id"作为属性,Waterline会自动为您添加ID或者像这样传递它 User.publishCreate({id:newGuy.id,name:newGuy.name});

答案 1 :(得分:0)

the documentation中所述,publishCreate方法需要一个对象,并且您传入的是标量值。理想情况下,您只需传入一个新创建的User对象,但如果您想限制发送的内容,您可以自己构建对象,如@ dkx22的示例所示。

相关问题