Moongoose 3.8.8是否支持$ position运算符? [英] Does Moongoose 3.8.8 support $position operator?

查看:71
本文介绍了Moongoose 3.8.8是否支持$ position运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Moongoose 3.8.8(最新版本)是否支持$ position( http ://docs.mongodb.org/manual/reference/operator/update/position/)来自MongoDB 2.6.0的运算符?

Does Moongoose 3.8.8 (the lastest version) support $position (http://docs.mongodb.org/manual/reference/operator/update/position/) operator from MongoDB 2.6.0?

在下面的代码示例中,新元素插入到数组userActivity.activities的末尾:

In the following code example the new elements is inserted in the end of the array userActivity.activities:

型号:

var userActivity = new schema({
    userId: {type:String, required:true, unique:true},
    activities: [activity]
});

var activity = new schema({
    act: {type: Number, required:true},
});

查询:

var activity = { act: 1 };

model.userActivity.update(
{ _id: dbact._id },
{ $push: { activities: {
                $each: [ activity ],
                $position: 0
            }
         }
},
function (err, numAffected) {
    if (!err) {
    // do something
    }
});

推荐答案

对于任何框架"实现,这实际上都没有关系,也没有关系,我也不介意解释原因.

This actually doesn't matter and never matters for any "framework" implementation and I do not mind explaining why.

每个单一的框架"(例如Mongoose,Mongoid,Doctrine,MongoEngine等,等等)基本上都建立在基本的驱动程序"实现之上,该实现在大多数情况下是由MongoDB工作人员自己开发的.因此,即使您需要深入"到某个级别才能使用这些本机"方法,基本功能也总是如此.

Every single "framework" ( such as Mongoose, Mongoid, Doctrine, MongoEngine, etc, etc, etc ) are all basically built upon a basic "driver" implementation that has in most cases been developedby the MongoDB staff themselves. So the basic functionality is always ther even if you need to "delve" down to a level in order to use those "native" methods.

因此,在这种情况下,这将是本机用法示例:

So here would be the native usage example in this case:

List.collection.update(
{},
{ "$push": {
    "list": {
      "$each": [ 1, 2, 3 ],
      "$position": 0 }
    }
},function(err,NumAffected) {
  console.log("done");

});

请注意模型中使用的收集"方法,该方法从驱动程序获取原始"收集详细信息.因此,您使用的是它的方法,而不是可能正在做其他处理的某些包装"方法.

Note the "collection" method used from the model, which is getting the "raw" collection details from the driver. So you are using it's method and not some "wrapped" method that may be doing additional processing.

下一个也是最基本的原因是,如果找不到所需的运算符的方法和应用程序,这是一个简单的事实.

The next and most basic reason is if you cannot find the method and application of the operators that you need the here is a simple fact.

每个框架中的方法和基本驱动程序方法所使用的每个单一操作本质上都是对基本API中"runCommand"方法的调用.因此,由于该基本调用无处不在(以某种形式,因为必须以某种形式存在),因此您可以使用 any 框架上的每种语言实现来完成您在MongoDB网站上发布的所有广告.

Every single operation as used by the methods in every framework and basic driver method is essentially a call to the "runCommand" method in the basic API. So since that basic call is available everywhere ( in some form or another, because it has to be ), then you can do everything that you find advertised on the MongoDB site with every language implementation on any framework.

但是对您的特定请求的简短调用是,因为这实际上不是方法调用,而只是传入的BSON参数的一部分,所以当然不受特定限制语言驱动程序才能真正使用它.

But the short call to your particular request is, since this is not actually a method call but is simply part of the BSON arguments as passed in, then of course there is no restriction by a particular language driver to actually use this.

因此,您可以使用这些新参数,而无需更新到最新版本.但实际上,您可能会获得一些不错的方法.

So you can use these new argument without of course updating to the most recent version. But you probably will get some nice methods to do so if you actually do.

这篇关于Moongoose 3.8.8是否支持$ position运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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