ObjectId与graphLookup mongodb nodejs中的字符串不匹配

时间:2019-10-12 06:08:40

标签: node.js mongodb mongoose nosql mean-stack

我的收藏在下面

import mysql.connector

mydb = mysql.connector.connect(

    host = "localhost",
    user = "root",
    passwd= "root",

)

mycursor = mydb.cursor()

mycursor.execute("CREATE DATABASE mydatabase")

---------------------------------------------------------------------------
MySQLInterfaceError                       Traceback (most recent call last)
C:\ANACONDA3\lib\site-packages\mysql\connector\connection_cext.py in cmd_query(self, query, raw, buffered, raw_as_string)
    471                                raw=raw, buffered=buffered,
--> 472                                raw_as_string=raw_as_string)
    473         except MySQLInterfaceError as exc:

MySQLInterfaceError: Can't create database 'mydatabase'; database exists

During handling of the above exception, another exception occurred:

DatabaseError                             Traceback (most recent call last)
<ipython-input-21-a74bf2818939> in <module>
     11 mycursor = mydb.cursor()
     12 
---> 13 mycursor.execute("CREATE DATABASE mydatabase")

C:\ANACONDA3\lib\site-packages\mysql\connector\cursor_cext.py in execute(self, operation, params, multi)
    264             result = self._cnx.cmd_query(stmt, raw=self._raw,
    265                                          buffered=self._buffered,
--> 266                                          raw_as_string=self._raw_as_string)
    267         except MySQLInterfaceError as exc:
    268             raise errors.get_mysql_exception(msg=exc.msg, errno=exc.errno,

C:\ANACONDA3\lib\site-packages\mysql\connector\connection_cext.py in cmd_query(self, query, raw, buffered, raw_as_string)
    473         except MySQLInterfaceError as exc:
    474             raise errors.get_mysql_exception(exc.errno, msg=exc.msg,
--> 475                                              sqlstate=exc.sqlstate)
    476         except AttributeError:
    477             if self._unix_socket:

DatabaseError: 1007 (HY000): Can't create database 'mydatabase'; database exists

});

我这样插入数据

const schema=Schema({
name: { type: String, required: true,maxlength:50 },
subcategory: [{ type: String, required: true,maxlength:100 }],
isActive: { type: Boolean, required: true ,default: 1},

现在,我正在尝试使用“ _id”(如下所示)在“子类别”上获取graphLookup

{
        "subcategory": [
            "5da084d13a61194bd4982947"
        ],
        "isActive": true,
        "_id": "5da084cb3a61194bd4982946",
        "name": "drinks",
        "__v": 0
    },
    {
        "subcategory": [],
        "isActive": true,
        "_id": "5da084d13a61194bd4982947",
        "name": "coke",
        "__v": 0
    },
    {
        "subcategory": [],
        "isActive": true,
        "_id": "5da084d63a61194bd4982948",
        "name": "fanta",
        "__v": 0
    }

但它不会给我导致pipline中“连接”字段的结果。它给出了这样的结果

 {
            $graphLookup: {
                from: 'category', // Use the customers collection
                startWith: '$subcategory', // Start looking at the document's `friends` property
                connectFromField: 'subcategory', // A link in the graph is represented by the friends property...
                connectToField: '_id', // ... pointing to another customer's _id property
                maxDepth: 1, // Only recurse one level deep
                as: 'connections' // Store this in the `connections` property
            }
        }

您可以看到连接中没有任何内容。它是空的。

0 个答案:

没有答案