简体   繁体   English

mongodb中客户端和服务器之间的搜索API

[英]Search API between client and server in mongodb

I have my server in nodejs and client in angularjs, mongodb(mongoose) as database. 我在nodejs中有我的服务器,在angularjs中有我的客户端,mongodb(mongoose)作为数据库。 I want my client to be able to make a search query with all the normal consitions put in like fixing few fields to certain values, search string contained in few of the fields etc 我希望我的客户能够使用所有正常条件进行搜索查询,例如将几个字段固定为某些值,将搜索字符串包含在几个字段中,等等。

query can be 查询可以

(value of field A can be 'x' or 'y') and 
(value of field B can range between dates P and Q) and
(string s contained in fields C or D or E)    few more

is there any npm plugin or standardisation I can follow to enrich my server side API and also directly put the expression while querying with out doing a map reduce with multiple queries(with lots of code). 我可以遵循任何npm插件或标准化来丰富我的服务器端API,也可以在查询时直接放置表达式,而无需通过多次查询(具有大量代码)进行map reduce。

Yes, there are a few. 是的,有几个。 I only know of those that work with Mongoose so if you're using another driver you may need to modify them a bit. 我只知道可与Mongoose一起使用的驱动程序,因此,如果您使用其他驱动程序,则可能需要对其进行一些修改。

With each of these you'll need to determine which to filter locally and which to let the server handle it. 对于每种方法,您都需要确定哪些要在本地过滤,哪些要由服务器处理。 Where you filter should depend largely on how much data you have. 过滤的位置应主要取决于您拥有多少数据。 Personally, it made more sense to abandon local filtering for my largest sets and simply rely on MongoDB to handle the workload. 就个人而言,放弃对我最大的集合的本地过滤更有意义,而仅依靠MongoDB来处理工作负载。

angoose angoose

Connecting Mongoose and Angular and More 连接猫鼬和Angular等

The original motive for Angoose project is to do away with the dual model declarations(server and client side) if we are building a rich model based SPA application using modern Javascript framework such as Angular and node.js. 如果我们正在使用Angular和node.js等现代Javascript框架构建基于模型的SPA应用程序,那么Angoose项目的原始动机就是消除双重模型声明(服务器和客户端)。 With both front end and backend using Javascript, Angoose allows the server side models and services to be used in the client side as if they reside in the client side. 通过使用Javascript的前端和后端,Angoose允许在客户端使用服务器端模型和服务,就像它们驻留在客户端一样。

Angoose depends on following frameworks and assumes you have basic familarities with them: Angoose依赖于以下框架,并假定您基本熟悉它们:

  • mongoose 猫鼬
  • express 表达
  • angular (optional, for non-angular app, jQuery is required) 角度的(可选,对于非角度应用,需要jQuery)

Mongoose Api Query 猫鼬Api查询

Mongoose plugin that takes a set of URL params and constructs a query for use in a search API. Mongoose插件,它采用一组URL参数并构造一个查询以供搜索API使用。 Also, worst project name ever. 另外,有史以来最差的项目名称。

If you use Mongoose to help serve results for API calls, you might be used to handling calls like: 如果您使用Mongoose帮助提供API调用的结果,则可能会习惯于处理以下调用:

/monsters?color=purple&eats_humans=true

mongoose-api-query handles some of that busywork for you. mongoose-api-query为您处理一些繁琐的工作。 Pass in a vanilla object (eg req.query) and query conditions will be cast to their appropriate types according to your Mongoose schema. 传入普通对象(例如req.query),查询条件将根据您的Mongoose模式强制转换为适当的类型。 For example, if you have a boolean defined in your schema, we'll convert the eats_humans=true to a boolean for searching. 例如,如果您在架构中定义了布尔值,我们会将eats_humans = true转换为布尔值以进行搜索。

It also adds a ton of additional search operators, like less than, greater than, not equal, near (for geosearch), in, and all. 它还会添加大量其他搜索运算符,例如小于,大于,不等于,接近(对于地理搜索),内部和全部。 You can find a full list below. 您可以在下面找到完整列表。

When searching strings, by default it does a partial, case-insensitive match. 搜索字符串时,默认情况下会进行不区分大小写的部分匹配。 (Which is not the default in MongoDB.) (这不是MongoDB中的默认值。)

Angular Bridge 角桥

Link models easily via a REST interface between Mongoose/Node-Express/Angular.js 通过Mongoose / Node-Express / Angular.js之间的REST接口轻松链接模型

Create, read, update, delete MongoDB collections via AngularJS. 通过AngularJS创建,读取,更新,删除MongoDB集合。

It uses : 它用 :

  • Mongoose for accessing to Mongodb 猫鼬访问Mongodb
  • Express for the routing 快速路由
  • AngularJS (with the $resource method) AngularJS(使用$ resource方法)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM