MongoVUE使用

Using Regular Expressions in Find|Fields|$where|Sorts with MongoVUE

1.Find:

Let us consider a collection of “users”. To find all the users where the username begins with the character “a”, we would write the following in the shell

db.users.find({"username":/^a/});

In MongoVUE, to fetch similar results from the “users” collection, you need to make a slight modification to the JSON query. After selecting “users” collection in the tree, you’ll need to enter the following (valid) JSON query in the Find popout box:

{"username": new RegExp("^a")}

Using Regular Expressions in MongoVUE

Multiple conditions like this:

  {Fldname:new RegExp("/^sgnrgn_/i"),Typename:new RegExp("/var/i")}

2.Fields:

At times you want to reduce extra data sent by the server to the client. For example, let us say you have an “Fieldview” collection and you wish to retrieve only Fldname and Typename.

In a SQL database, you would achieve this by

   SELECT Fldname,Typename FROM Fieldview

instead of

   SELECT * FROM Fieldview

To achieve the same affect in MongoDB, simply mention the items you wish to fetch (within the resulting documents) in the “Fields” popout box.

3.$where:

In MongoDB, “$where” is used to specify arbitrary Javascript that allows one to run more specialized queries, especially the boolean “OR” criteria.

Lets continue with the example of our “address” collection that we first discussed under Find. Documents in this collection contain address information, for example:

{
	"Street":"123 ABC Street",
	"Street2": "Search Boulevard",
	"City": "Allentown",
	"State": "PA",
	"Country": "United States"
}

Now, if we were to fetch all the address in Allentown and Pittsburgh only, we would specify a JavaScript statement (condition, that evaluates to true or false) as follows:

image

 

This same can also be expressed in the form of a JavaScript function:

image

 

Please note: You could achieve the same results by specifying your JavaScript inside the “Find” query (see pic below). Also note that if you specify such a condition in both the “Find” popout box, and the “Where” popout box, then the JavaScript in “Where” takes precedence and overwrites those specified under “Find”.

image

4.Sorts:

Sort is easy. When you want your results to be sorted in a particular order, you just specify the sorting criteria in a Json object.

Lets say you want to retrieve all documents from our “address” collection in the alphabetical order of “State” names, you would simply enter the appropriate Json in the Sort popout box as shown below:

image

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值