sails.js从集合水线中删除所有成员

Jaf*_*aei 2 collections node.js sails.js waterline sails-mongo

我想删除集合具有的所有成员,但是我不想将每个成员都传递ID.member()方法。 水线文件说明了删除特定成员的方法,例如:

await User.removeFromCollection(3, 'pets')
.members([99,98]);
Run Code Online (Sandbox Code Playgroud)

我想做某事:

await User.removeFromCollection(3, 'pets')
.members(['*']);
Run Code Online (Sandbox Code Playgroud)

Can*_*nis 6

据我所知,这应该在.destroy()没有条件的情况下使用。

编辑(2019-07-10):根据noobular的评论添加了空的curlies

await User.destroy({});                // Removes all records from your User collection

await User.destroy({name:'Bill'};    // Removes all records from your User collection
                                        where the 'name' is 'Bill'
Run Code Online (Sandbox Code Playgroud)

文件: .destroy()

更新资料

在您指出我误解了您的问题之后,我想出了这个解决方案。用于.removeFromCollection()状态的docs 声明,传递父ID的数组将删除指定集合中的所有子项,但这似乎不起作用。

但是,我确实找到了使用您的可行解决方案.replaceCollection()

await User.replaceCollection(3, 'pets', []);

OR

await User.replaceCollection(3, 'pets').members([]);
Run Code Online (Sandbox Code Playgroud)

传入空数组将用空数组替换当前的关联数组,清除当前的关联。

文件: .replaceCollection()