首页 \ 问答 \ Mongodb查询中的未定义值(Undefined value in Mongodb query)

Mongodb查询中的未定义值(Undefined value in Mongodb query)

我想通过Mongodb查询从服务器端向客户端发送json数据。 我已经处理了我对数据库和连接内容的查询。

function mongoDbHandleLoad()
{
    MongoClient.connect(MongoDBURL, function(err, db)
    {

        /*
         db.createCollection('user', {strict:true},  function(err, collection) {
         if(err)
         return console.dir(err);
         });
         */

        db.collection('user', function(err, collection) {
            if(!err)
            {
                collection.find().toArray(function(err, docs) {
                    if(!err)
                    {
                        var intCount = docs.length;
                        var responseBody;
                        if(intCount > 0)
                        {
                            console.log("responseBody in mongodb handle", JSON.stringify(docs[docs.length-1]));
                            return JSON.stringify(docs[docs.length-1]);
                        }
                    }
                });
            }
        });
    });

    /*
        if(docs != null)
        {
            console.log("docs", docs);
            return resParam.json(docs); //return the first document found
        }
    */
}

我使用此代码段成功发送了测试json数据。

if(str.localeCompare(controlPathDatabaseLoad) == 0)
{
    console.log("controlPathDatabaseLoad");
    mongoDbHandleLoad();
    res.setHeader('Content-Type', 'application/json');
    res.writeHead(res.statusCode);
    res.write(JSON.stringify(testJSON));
    res.end();
}

当我想在mongoDbHandleLoad()函数内发送数据“JSON.stringify(docs [docs.length-1])”时,即使我用回调改变了函数,我也无法正常工作。 我从mongoDbHandleLoad函数中获取未定义的值。 如何修改代码以获取“JSON.stringify(docs [docs.length-1])”的正确值。

提前致谢,


I want to send a json data via Mongodb query from the server side to client side. I have handled my query of database and connection stuff as you can see.

function mongoDbHandleLoad()
{
    MongoClient.connect(MongoDBURL, function(err, db)
    {

        /*
         db.createCollection('user', {strict:true},  function(err, collection) {
         if(err)
         return console.dir(err);
         });
         */

        db.collection('user', function(err, collection) {
            if(!err)
            {
                collection.find().toArray(function(err, docs) {
                    if(!err)
                    {
                        var intCount = docs.length;
                        var responseBody;
                        if(intCount > 0)
                        {
                            console.log("responseBody in mongodb handle", JSON.stringify(docs[docs.length-1]));
                            return JSON.stringify(docs[docs.length-1]);
                        }
                    }
                });
            }
        });
    });

    /*
        if(docs != null)
        {
            console.log("docs", docs);
            return resParam.json(docs); //return the first document found
        }
    */
}

And I send a test json data successfully with this code snippet.

if(str.localeCompare(controlPathDatabaseLoad) == 0)
{
    console.log("controlPathDatabaseLoad");
    mongoDbHandleLoad();
    res.setHeader('Content-Type', 'application/json');
    res.writeHead(res.statusCode);
    res.write(JSON.stringify(testJSON));
    res.end();
}

When I wanted to send the data "JSON.stringify(docs[docs.length-1])" inside of mongoDbHandleLoad() function, even though I changed function with callback, I couldn't do properly. I take undefined value from mongoDbHandleLoad function. How can I modify to code to take proper value of "JSON.stringify(docs[docs.length-1])".

Thanks in advance,


原文:https://stackoverflow.com/questions/42754949
更新时间:2024-01-19 11:01

最满意答案

我能用主分支/集成流进行这个新开发流(子子分支)的同步(重新基础和交付)吗?

您将能够从subdev流传subdev您想要的任何其他分支。 Integration甚至来自另一个项目的流(其中包含相同的UCM组件)

但是,您只能从直接父流(此处为dev流)进行rebase。

也可以看看:

是否可以跨两个具有与其父级相同的集成流的开发流进行同步。

是,仅通过传递:您可以传递到与源流处于同一级别的目标流。
实际上,您可以传递到任何流(但如果目标流是源流的直接子流,则建议使用rebase)。


Will I be able to do synchronization (re-base and deliver) of this new development stream (sub-sub-branch) with the main branch/integration stream ?

You will be able to deliver from subdev stream to any other branch you want. Integration or even a stream from another project (with the same UCM components in it)

You will be able to rebase, however, only from the direct parent stream (dev stream here).

See also:

is it possible to synchronize across two development streams that have the same integration stream as their parent.

Yes, through deliver only: you can deliver to a destination stream which is at the same level as the source stream.
Actually, you can deliver to any stream (but if the destination stream is a direct child of the source stream, then a rebase is recommended).

相关问答

更多
  • 如果你是给这三个加的float 那么
    应该在这个div的 class上面加 float:both
  • 简短的回答是JSR-133在解释中过分 。 这不是一个严重的问题,因为JSR-133是不属于语言或JVM标准的非规范性文档。 Java存储模型是根据诸如可见性,原子性,在关系之前发生的事情来正式定义的,这正好解释了什么线程必须看到什么,在使用精确(数学)定义的其他动作和其他关系之前必须发生什么动作模型。 没有正式定义的行为可能是随机的,或者在某些硬件和JVM实现的实践中定义明确 - 但是当然,您不应该依赖这一点,因为它可能会在未来发生变化,并且您永远无法确定除非您编写了JVM并且非常了解硬件语义,否则它首先 ...
  • 您首先需要一个配置为在该特定日期选择元素的视图:使用基于时间的选择规则配置规范 : element /myPath/... /main/{!created_since(16-Sep-2009)} element /myPath/... /main/LATEST 我建议使用动态视图,因为您可以轻松调整所述配置规范,直到您看到所需的版本,并在每次配置规范修改后快速刷新视图。 正确设置视图后,您可以使用: 一个简单的查找查询,列出所有未标记特定标签的版本 或者必须首先选择适当的脚本 (在C:\Program F ...
  • 我看不到主分支上的文件夹,它仍然指向项目分支。 检查你的配置规范(它应该只包含元素* / main / LATEST) 检查一下,正如我之前解释的那样 ,你合并的代码的父文件夹也是合并的(也是project_brnch和main之间的红色箭头),否则你将无法在/main看到合并的代码。 I can't see the folder on main branch and it still pointing to project branch. check your config spec (it should ...
  • System.exit(1)阻止finally子句运行。 基本上,在try / catch之后执行finally块,无论try或catch是正常返回还是异常返回。 但是,System.exit会阻止块返回。 而(真); 显然会无限期地阻止。 只是假设了一会儿(真实); 是一个更有意义的东西的存根:) System.exit(1) prevents the finally clause from running. Basically a finally block is executed after a tr ...
  • AFAIK,这是不可能的。 我处理的方式是通过填写(自动)模板。 但我也使用不同的观点; 视图是一次性的,我会定期重建我的观点(每周,每两周,如果我需要确保构建的清洁度,有时一天几次)。 我会向你展示我的剧本,但是它们中有很多,并且它们相互错综复杂地交织在一起,并且与我们的工作环境相互交织(对于许多主要版本中的每一个,多个但是重叠的VOB)产品,由CM提供的配置规范的一些部分和自定义前导码来识别我正在工作的东西)。 我们已经使用ClearCase大约18年了。 最终结果是错误修复分支的配置规范,如下所示: ...
  • 该按钮仅在您的视图配置(即您的配置规范列出的基线列表)与您的流配置不同时才有效。 同样更新视图的事实只是视图作为快照的副作用。 对于快照视图(即磁盘上的视图): 仅更新视图将仅根据所述视图的配置规范更新内容(未更改) 将视图与流同步将触发更新,该更新将基于视图的更新配置规范(即,在读取关联流的配置后,为您自动重写的视图的配置规范) 它更新“集成视图”的事实只是因为您的视图恰好与Integration Stream相关联。 但正如我之前关于“ ClearCase中的集成流与集成视图 ”的回答所示,可能存在许多 ...
  • 然后不要打扰GUI:通过带有cleartool的shell尝试它。 请参阅“ 无法创建clearcase组件? ”(使用动态视图,但您可以调整使用快照视图)。 Then don't bother with the GUI: try it through a shell with cleartool. See "can't create clearcase component?" (which is using a dynamic view, but you can adapt to use your sna ...
  • 我能用主分支/集成流进行这个新开发流(子子分支)的同步(重新基础和交付)吗? 您将能够从subdev流传subdev您想要的任何其他分支。 Integration甚至来自另一个项目的流(其中包含相同的UCM组件) 但是,您只能从直接父流(此处为dev流)进行rebase。 也可以看看: “ ClearCase UCM层次结构 ” “ UCM明确案例:一个项目中的流的Hiereachy与多个项目 ” “ ClearCase:有可能选择性地交付或改变吗? ” 是否可以跨两个具有与其父级相同的集成流的开发流进行同 ...
  • public void clear() { textvalue="";// set textvalue to null mBitmapPaint = new Paint(Paint.DITHER_FLAG); mBitmap = Bitmap.createBitmap(320,480,Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); path = new Path(); //reset drawing ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。