Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在仍然使用mongoose进行模式定义时,是否有方法访问mongodb node.js驱动程序功能?_Node.js_Mongodb_Express_Mongoose - Fatal编程技术网

在仍然使用mongoose进行模式定义时,是否有方法访问mongodb node.js驱动程序功能?

在仍然使用mongoose进行模式定义时,是否有方法访问mongodb node.js驱动程序功能?,node.js,mongodb,express,mongoose,Node.js,Mongodb,Express,Mongoose,我真正想做的是根据文档的属性值为文档的筛选和字符串匹配创建索引 我知道mongodb内置了一些操作符,比如$text,它们对这类功能非常有帮助 我不确定在使用mongoose时如何访问这些操作符,或者是否需要使用任何方法来访问它们 我想使用mongoose来定义模式和模型,但需要原生mongodb的功能 这可能吗?以下是我的观点,如果我遗漏了什么,或者需要修改或解释什么,请添加: 1. You will still be able to use mongoDB's native functio

我真正想做的是根据文档的属性值为文档的筛选和字符串匹配创建索引

我知道mongodb内置了一些操作符,比如$text,它们对这类功能非常有帮助

我不确定在使用mongoose时如何访问这些操作符,或者是否需要使用任何方法来访问它们

我想使用mongoose来定义模式和模型,但需要原生mongodb的功能


这可能吗?

以下是我的观点,如果我遗漏了什么,或者需要修改或解释什么,请添加:

1.  You will still be able to use mongoDB's native functionalities on using Mongoose models.
2.  Mongoose is a kind of wrapper on top of native mongoDB-driver.
3.  It would be very useful if you want to have schema based collections/data.
4.  Additionally it would provide few more features than native mongoDB's driver. You might see few syntax differences between those two.
5.  Few examples like `.findByIdAndUpdate()` & `.populate()` are mongoose specific, which has equivalent functionalities available in mongoDB driver/mongoDB as well.  
6.  In general it's quiet common to define mongoose models and use those over mongoDB's functionality in coding(As in node.js - You would write all of your same DB queries on Mongoose models, queries that you execute in DB).
第2点:

Mongoose是一个对象文档建模(ODM)层,位于节点MongoDB驱动程序的顶部。如果您来自SQL,它类似于关系数据库的ORM

第3点:

在代码中,如果您使用mongoose模型来实现您的写查询,除非您在模型中定义了一个字段,否则它不会被添加到DB中,尽管您在请求中传递了它。此外,您还可以执行多项操作,如使字段唯一/必需等。。这使您的mongoDB数据看起来像是基于模式的。如果你收集的数据更像是随机数据(newsfeed之类的东西,每个文档的字段都不相同&你无法预测数据),那么你可能不介意使用mongoose

第6点:

假设您使用mongo shell或mongo compass/robo3T这样的客户端,并执行如下查询:

    db.getCollection('yourCollection').find(
    {
        $text: {
            $search: 'employeeName',
            $diacriticSensitive: false
        },
        country: 'usa'
    },
    {
        employee_id: 1,
        name: 1
    }
).sort({ score: { $meta: 'textScore' } });
在mongoose模型上也可以这样做(因为已经定义了CollectionModel):

在使用mongoose时,您会在写操作而不是读操作上看到更多的关键功能差异,尽管以上所有内容都与性能无关——如果您问我,我可以说,您可能会看到使用mongoose会带来很多性能提升


参考:

以下是我的观点,如果我遗漏了什么,或者需要修改或解释什么,请添加:

1.  You will still be able to use mongoDB's native functionalities on using Mongoose models.
2.  Mongoose is a kind of wrapper on top of native mongoDB-driver.
3.  It would be very useful if you want to have schema based collections/data.
4.  Additionally it would provide few more features than native mongoDB's driver. You might see few syntax differences between those two.
5.  Few examples like `.findByIdAndUpdate()` & `.populate()` are mongoose specific, which has equivalent functionalities available in mongoDB driver/mongoDB as well.  
6.  In general it's quiet common to define mongoose models and use those over mongoDB's functionality in coding(As in node.js - You would write all of your same DB queries on Mongoose models, queries that you execute in DB).
第2点:

Mongoose是一个对象文档建模(ODM)层,位于节点MongoDB驱动程序的顶部。如果您来自SQL,它类似于关系数据库的ORM

第3点:

在代码中,如果您使用mongoose模型来实现您的写查询,除非您在模型中定义了一个字段,否则它不会被添加到DB中,尽管您在请求中传递了它。此外,您还可以执行多项操作,如使字段唯一/必需等。。这使您的mongoDB数据看起来像是基于模式的。如果你收集的数据更像是随机数据(newsfeed之类的东西,每个文档的字段都不相同&你无法预测数据),那么你可能不介意使用mongoose

第6点:

假设您使用mongo shell或mongo compass/robo3T这样的客户端,并执行如下查询:

    db.getCollection('yourCollection').find(
    {
        $text: {
            $search: 'employeeName',
            $diacriticSensitive: false
        },
        country: 'usa'
    },
    {
        employee_id: 1,
        name: 1
    }
).sort({ score: { $meta: 'textScore' } });
在mongoose模型上也可以这样做(因为已经定义了CollectionModel):

在使用mongoose时,您会在写操作而不是读操作上看到更多的关键功能差异,尽管以上所有内容都与性能无关——如果您问我,我可以说,您可能会看到使用mongoose会带来很多性能提升

参考: