简单的DocumentDb存储过程 [英] Simple DocumentDb stored procedure

查看:58
本文介绍了简单的DocumentDb存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简单的DocumentDb存储过程,以更好地理解其概念.在此示例中,我试图返回所有女性"用户.我需要担心自己返回一个匹配的文档还是多个文档?

I'm trying to create a simple DocumentDb stored procedure to better understand its concepts. In this example, I'm trying to return a all "Female" users. Do I need to concern myself with returning a single matching document or multiple documents?

这是我的用户对象的样子:

Here's what my user object looks like:

{
   "id": "e85ee3d7-44a5-4250-a116-686e1c2a10f5"
   "firstName": "Jane",
   "lastName": "Doe",
   "gender": "F"
}

这是到目前为止我的storageproc的样子:

And here's what my storedproc looks like so far:

function(gender) { 

   var context = getContext();
   var response = context.getResponse();
   var collection = context.getCollection();
   var collectionLink = collection.getSelfLink();

   var filterQuery = "SELECT * FROM c WHERE c.gender = '" + gender + "'";
   // Now what???
}

我想返回所有女性用户.可能有一个或10,000个女性用户.

I'd like to return ALL female users. There may be one or 10,000 female users.

非常感谢您对这个简单的DocumentDb存储过程的帮助.谢谢.

I'd appreciate your help with this simple DocumentDb stored procedure. Thanks.

推荐答案

您在正确的轨道上.

下一步是在集合上运行filterQuery,然后将查询响应放入响应变量中.

The next steps would be to run your filterQuery on the collection, and then place the query response in to the response variable.

例如:

function(gender) {
  var context = getContext();
  var response = context.getResponse();
  var collection = context.getCollection();
  var collectionLink = collection.getSelfLink();

  var filterQuery = 'SELECT * FROM c WHERE c.gender = "' + gender + '"';

  collection.queryDocuments(collectionLink, filterQuery, {},
    function(err, documents) {
      response.setBody(response.getBody() + JSON.stringify(documents));
    }
  );
}

您可以在DocumentDB的网站上找到有关存储过程的更多示例和文档:

You can find some more samples and documentation on stored procedures on DocumentDB's website: http://azure.microsoft.com/en-us/documentation/articles/documentdb-programming/

这篇关于简单的DocumentDb存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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