代码之家  ›  专栏  ›  技术社区  ›  David Sherret

在一个存储过程中使用WHERE子句通过查询创建然后检索文档

  •  2
  • David Sherret  · 技术社区  · 7 年前

    在存储过程中,我发现 collection.queryDocuments(...) WHERE

    例如,以简化的存储过程为例:

    function createThenQuery() {
        const collection = getContext().getCollection();
        const collectionLink = collection.getSelfLink();
        const response = getContext().getResponse();
        const document = { name: "Some Name" };
    
        collection.createDocument(collectionLink, document, (err, createdDocument) => {
            const query = `SELECT * FROM c WHERE c.name='${document.name}'`;
            collection.queryDocuments(collectionLink, query, {}, (err, retrievedDocs) => {
                console.log(retrievedDocs.length);
            });
        });
    }
    

    这将输出以下内容:

    1st run: 0
    2nd run: 1
    3rd run: 2
    etc...
    

    但是,当我移除 哪里 条款( SELECT * FROM c )它输出以下内容:

    1st run: 1
    2nd run: 2
    3rd run: 3
    etc...
    

    我希望在这两种情况下都有第二个输出。有没有什么方法可以修复这个问题,让它返回我在使用 哪里

    我猜这可能是因为某些索引在存储过程完成运行并提交事务之前没有被更新?也许有办法禁用或强制更新?在本例中,它是一个一次性脚本,因此如果运行稍微慢一点就可以了。

    0 回复  |  直到 7 年前
    推荐文章