Author Archives: Robins

Error installing OS X virtual machine vcu-0: verify vmcore / VM / main / physmem_ monitor.c:1123

Create a new virtual machine, select Apple MacOS X 10.10 as the operating system of the client, and other parameters can be set by default.

Pay attention not to rush to open the client after it is built, because if you open it directly, you will find that the new client will not start.

Read Mac OS X Unlocker for VMware v2.0 readme.txt You will find the answer. The default OSX client set up by VMware 11 will crash directly. There are two solutions:

Replace VM with HW 10

Or edit VMX file and add smc.version = 0 

Go to the client’s installation directory and open the VMX file. For example, if your client’s name is OSX, this file is OSX.vmx ,

You will see an SMC parameter:

smc.present = “TRUE”

hold smc.version =0 load the line after this parameter, save and exit. Restart the client and found it started normally.

Please specify which branch you want to merge with

$git pull

 

$ git pull
warning: no common commits
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (5/5), done.
From github.com:nonfuxinyang/android-study
 * [new branch]      master     -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

Seeing the second tip, we now know a solution. That is to specify the link relationship between the current working directory, working branch, and remote warehouse and branch. ≪ BR & gt;

for example, we set the master branch corresponding to the remote warehouse

git branch — set upstream master origin / Master

so every time we want to push or pull, we just need to enter Git push or git pull.

Before that, we have to specify the remote branch that we want to push or pull.

git push origin master

git pull origin master.

 

 

 

 

Solve the problem of error: cannot pass objects of non trivially copyable type ‘STD:: String’ in C / C + +

catalog

1. Problem description 2. Cause analysis 3. Solution

1. Problem description

When running the program, the compiler reports an error:

error: cannot pass objects of non-trivially-copyable type ‘std::string {aka struct std::basic_ string}’ through ‘…’ |

2. Cause analysis

The error is displayed on this line:

printf("%c %s %lld %lld\n", p, edges, ver, edge);

Where edges is of string type.

Grammar:

const char *c_ str();c_ Str() function returns a pointer to a normal C string, the content of which is the same as that of this string string. In order to be compatible with C, there is no string type in C, so it must pass the member function C of string class object_ Str () converts a string object to a string style in C.

3. Solutions

In use, add C_ str();

printf("%c %s %lld %lld\n", p, edges.c_str(), ver, edge);

[oh-my-zsh] Insecure completion-dependent directories detected

Question content:

[oh-my-zsh] Insecure completion-dependent directories detected:
drwxrwxr-x  3 st  admin   96 11 26 09:08 /usr/local/share/zsh
drwxrwxr-x  4 st  admin  128 11 26 10:16 /usr/local/share/zsh/site-functions

[oh-my-zsh] For safety, we will not load completions from these directories until
[oh-my-zsh] you fix their permissions and ownership and restart zsh.
[oh-my-zsh] See the above list for directories with group or other writability.

[oh-my-zsh] To fix your permissions you can do so by disabling
[oh-my-zsh] the write permission of "group" and "others" and making sure that the
[oh-my-zsh] owner of these directories is either root or your current user.
[oh-my-zsh] The following command may help:
[oh-my-zsh]     compaudit | xargs chmod g-w,o-w

[oh-my-zsh] If the above didn't help or you want to skip the verification of
[oh-my-zsh] insecure directories you can set the variable ZSH_DISABLE_COMPFIX to
[oh-my-zsh] "true" before oh-my-zsh is sourced in your zshrc file.

It is necessary to add Zsh through content expression_ DISABLE_ Compfix = “true” in front of the contents of the zshrc file

Operation steps:

vim ~/.zshrc

File addition

ZSH_DISABLE_COMPFIX="true"

Execute the command after saving the file

source ~/.zshrc

Completion o ( ̄ ▽  ̄) d ✨✨✨

Matlab prompt error

Enter the following code
(1)

a = [1 2;3 4];
a(6) = 7;

Prompt:
attempt to grow array along ambiguous dimension.
in Chinese:
attempt to grow large array along fuzzy dimension

The following codes are correct
(2)

a = [1 2;3 4];
a(5, 8) = 7;

Why is it that code (1) is wrong and code (2) is at a loss when it exceeds the predefined matrix size?

The cause of the problem is as indicated in the prompt

, the program cannot determine the dimension of the matrix.
What do you mean?
Although the code segment (2) exceeds the predefined matrix dimension: 2-by-2, it can determine the matrix dimension after an assignment (a (5, 8) = 7): 5-by-8.
The code segment (1) is a linear index -- 6, which is converted to a matrix subscript of 2-by-3 or 3-by-2??
The computer doesn't know, so it reports an error. " attempts to grow data along fuzzy dimensions ". This tip, feel very awkward, in fact, is very correct .

The scheme failed with ‘command’ failed

PIP install pylibmc installation failure and its solution. During installation, the following errors are reported, and there may be other errors, similar to the following:

pip install pylibmc==1.6.1
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pylibmc==1.6.1
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/a7/0c/f7a3af34b05c167a69ed1fc330b06b658dac4ab25b8632c52d1022dd5337/pylibmc-1.6.1.tar.gz (64 kB)
Building wheels for collected packages: pylibmc
  Building wheel for pylibmc (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /Users/yangchangjia/PycharmProjects/Nox/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/x7/zprpyfhx3h3g5qs3c_z_gxqc0000gn/T/pip-install-14fh8zn_/pylibmc/setup.py'"'"'; __file__='"'"'/private/var/folders/x7/zprpyfhx3h3g5qs3c_z_gxqc0000gn/T/pip-install-14fh8zn_/pylibmc/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/x7/zprpyfhx3h3g5qs3c_z_gxqc0000gn/T/pip-wheel-73t1n0ft
       cwd: /private/var/folders/x7/zprpyfhx3h3g5qs3c_z_gxqc0000gn/T/pip-install-14fh8zn_/pylibmc/
  Complete output (28 lines):
  /private/var/folders/x7/zprpyfhx3h3g5qs3c_z_gxqc0000gn/T/pip-install-14fh8zn_/pylibmc/setup.py:98: DeprecationWarning: 'U' mode is deprecated
    with open("README.rst", "U", encoding="utf-8") as r:
  /private/var/folders/x7/zprpyfhx3h3g5qs3c_z_gxqc0000gn/T/pip-install-14fh8zn_/pylibmc/setup.py:100: DeprecationWarning: 'U' mode is deprecated
    with open("src/pylibmc-version.h", "U", encoding="utf-8") as r:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.15-x86_64-3.8
  creating build/lib.macosx-10.15-x86_64-3.8/pylibmc
  copying src/pylibmc/autoconf.py -> build/lib.macosx-10.15-x86_64-3.8/pylibmc
  copying src/pylibmc/pools.py -> build/lib.macosx-10.15-x86_64-3.8/pylibmc
  copying src/pylibmc/client.py -> build/lib.macosx-10.15-x86_64-3.8/pylibmc
  copying src/pylibmc/__init__.py -> build/lib.macosx-10.15-x86_64-3.8/pylibmc
  copying src/pylibmc/test.py -> build/lib.macosx-10.15-x86_64-3.8/pylibmc
  copying src/pylibmc/consts.py -> build/lib.macosx-10.15-x86_64-3.8/pylibmc
  copying src/pylibmc/__main__.py -> build/lib.macosx-10.15-x86_64-3.8/pylibmc
  running build_ext
  building '_pylibmc' extension
  creating build/temp.macosx-10.15-x86_64-3.8
  creating build/temp.macosx-10.15-x86_64-3.8/src
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include -DUSE_ZLIB -I/Users/yangchangjia/PycharmProjects/Nox/venv/include -I/Users/yangchangjia/.pyenv/versions/3.8.6/include/python3.8 -c src/_pylibmcmodule.c -o build/temp.macosx-10.15-x86_64-3.8/src/_pylibmcmodule.o -fno-strict-aliasing -std=c99
  In file included from src/_pylibmcmodule.c:34:
  src/_pylibmcmodule.h:42:10: fatal error: 'libmemcached/memcached.h' file not found
  #include <libmemcached/memcached.h>
           ^~~~~~~~~~~~~~~~~~~~~~~~~~
  1 error generated.
  error: command 'clang' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for pylibmc
  Running setup.py clean for pylibmc
Failed to build pylibmc
Installing collected packages: pylibmc
    Running setup.py install for pylibmc ... error
    ERROR: Command errored out with exit status 1:
     command: /Users/yangchangjia/PycharmProjects/Nox/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/x7/zprpyfhx3h3g5qs3c_z_gxqc0000gn/T/pip-install-14fh8zn_/pylibmc/setup.py'"'"'; __file__='"'"'/private/var/folders/x7/zprpyfhx3h3g5qs3c_z_gxqc0000gn/T/pip-install-14fh8zn_/pylibmc/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/x7/zprpyfhx3h3g5qs3c_z_gxqc0000gn/T/pip-record-tox14kc6/install-record.txt --single-version-externally-managed --compile --install-headers /Users/yangchangjia/PycharmProjects/Nox/venv/include/site/python3.8/pylibmc
         cwd: /private/var/folders/x7/zprpyfhx3h3g5qs3c_z_gxqc0000gn/T/pip-install-14fh8zn_/pylibmc/
    Complete output (28 lines):
    /private/var/folders/x7/zprpyfhx3h3g5qs3c_z_gxqc0000gn/T/pip-install-14fh8zn_/pylibmc/setup.py:98: DeprecationWarning: 'U' mode is deprecated
      with open("README.rst", "U", encoding="utf-8") as r:
    /private/var/folders/x7/zprpyfhx3h3g5qs3c_z_gxqc0000gn/T/pip-install-14fh8zn_/pylibmc/setup.py:100: DeprecationWarning: 'U' mode is deprecated
      with open("src/pylibmc-version.h", "U", encoding="utf-8") as r:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.15-x86_64-3.8
    creating build/lib.macosx-10.15-x86_64-3.8/pylibmc
    copying src/pylibmc/autoconf.py -> build/lib.macosx-10.15-x86_64-3.8/pylibmc
    copying src/pylibmc/pools.py -> build/lib.macosx-10.15-x86_64-3.8/pylibmc
    copying src/pylibmc/client.py -> build/lib.macosx-10.15-x86_64-3.8/pylibmc
    copying src/pylibmc/__init__.py -> build/lib.macosx-10.15-x86_64-3.8/pylibmc
    copying src/pylibmc/test.py -> build/lib.macosx-10.15-x86_64-3.8/pylibmc
    copying src/pylibmc/consts.py -> build/lib.macosx-10.15-x86_64-3.8/pylibmc
    copying src/pylibmc/__main__.py -> build/lib.macosx-10.15-x86_64-3.8/pylibmc
    running build_ext
    building '_pylibmc' extension
    creating build/temp.macosx-10.15-x86_64-3.8
    creating build/temp.macosx-10.15-x86_64-3.8/src
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include -DUSE_ZLIB -I/Users/yangchangjia/PycharmProjects/Nox/venv/include -I/Users/yangchangjia/.pyenv/versions/3.8.6/include/python3.8 -c src/_pylibmcmodule.c -o build/temp.macosx-10.15-x86_64-3.8/src/_pylibmcmodule.o -fno-strict-aliasing -std=c99
    In file included from src/_pylibmcmodule.c:34:
    src/_pylibmcmodule.h:42:10: fatal error: 'libmemcached/memcached.h' file not found
    #include <libmemcached/memcached.h>
             ^~~~~~~~~~~~~~~~~~~~~~~~~~
    1 error generated.
    error: command 'clang' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/yangchangjia/PycharmProjects/Nox/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/x7/zprpyfhx3h3g5qs3c_z_gxqc0000gn/T/pip-install-14fh8zn_/pylibmc/setup.py'"'"'; __file__='"'"'/private/var/folders/x7/zprpyfhx3h3g5qs3c_z_gxqc0000gn/T/pip-install-14fh8zn_/pylibmc/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/x7/zprpyfhx3h3g5qs3c_z_gxqc0000gn/T/pip-record-tox14kc6/install-record.txt --single-version-externally-managed --compile --install-headers /Users/yangchangjia/PycharmProjects/Nox/venv/include/site/python3.8/pylibmc Check the logs for full command output.

Solution:

brew install libmemcached
pip install wheel
pip install pylibmc

Installation successful:

pip install pylibmc
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pylibmc
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/a7/0c/f7a3af34b05c167a69ed1fc330b06b658dac4ab25b8632c52d1022dd5337/pylibmc-1.6.1.tar.gz (64 kB)
Building wheels for collected packages: pylibmc
  Building wheel for pylibmc (setup.py) ... done
  Created wheel for pylibmc: filename=pylibmc-1.6.1-cp38-cp38-macosx_10_15_x86_64.whl size=33323 sha256=9a8ecb4933b8a455b7ffe9db042011f3a9865c18441b8e5204d843bc0e6da1a3
  Stored in directory: /Users/yangchangjia/Library/Caches/pip/wheels/a1/8e/7e/d1b6684901c01de15a45efb8b5172c1dc7b9c6a7386d369839
Successfully built pylibmc
Installing collected packages: pylibmc
Successfully installed pylibmc-1.6.1

Multi-object editing not supported error resolution

error message

resolvent

Add a property [caneditmultipleobjects] before your editor class declaration.

When an editor without this attribute selects multiple objects, it will prompt “multi object editing not supported”, and other drawing errors will not be displayed.

Note: the script file of customeditor must be placed in the assets / editor folder in the project, and using unityeditor; must be added to the reference of the script header file;.

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(TestLightmapsHolder))]
[CanEditMultipleObjects]//add this
public class TestLightmapsHolderEditor : Editor
{
    public override void OnInspectorGUI()
    {
        TestLightmapsHolder holder = target as TestLightmapsHolder;
        base.OnInspectorGUI();
        if (GUILayout.Button("Save light mapping"))
            holder.SaveLightmaps();
    }
}

ImportError: No module named google.protobuf.internal

>>> import caffe
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “/home/ubuntu/caffe/python/caffe/__init__.py”, line 1, in <module>
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
File “/home/ubuntu/caffe/python/caffe/pycaffe.py”, line 15, in <module>
import caffe.io
File “/home/ubuntu/caffe/python/caffe/io.py”, line 8, in <module>
from caffe.proto import caffe_pb2
File “/home/ubuntu/caffe/python/caffe/proto/caffe_pb2.py”, line 6, in <module>
from google.protobuf.internal import enum_type_wrapper
ImportError: No module named google.protobuf.internal

Solution
sudo apt-get install python-protobuf

TypeError: db.collection is not a function

1. Error description

F:\nodejs>node insertData.js
(node:10028) DeprecationWarning: current URL string parser is deprecated, and wi
ll be removed in a future version. To use the new parser, pass option { useNewUr
lParser: true } to MongoClient.connect.
���ӳɹ���
F:\nodejs\node_modules\[email protected]@mongodb\lib\operations\mongo_client_ops.js
:439
      throw err;
      ^

TypeError: db.collection is not a function
    at writeData (F:\nodejs\insertData.js:5:22)
    at F:\nodejs\insertData.js:19:2
    at result (F:\nodejs\node_modules\[email protected]@mongodb\lib\utils.js:414:17
)
    at executeCallback (F:\nodejs\node_modules\[email protected]@mongodb\lib\utils.
js:406:9)
    at err (F:\nodejs\node_modules\[email protected]@mongodb\lib\operations\mongo_c
lient_ops.js:285:5)
    at connectCallback (F:\nodejs\node_modules\[email protected]@mongodb\lib\operat
ions\mongo_client_ops.js:240:5)
    at process.nextTick (F:\nodejs\node_modules\[email protected]@mongodb\lib\opera
tions\mongo_client_ops.js:436:7)
    at process._tickCallback (internal/process/next_tick.js:61:11)

F:\nodejs>node insertData.js
(node:4900) DeprecationWarning: current URL string parser is deprecated, and wil
l be removed in a future version. To use the new parser, pass option { useNewUrl
Parser: true } to MongoClient.connect.
���ӳɹ���
F:\nodejs\node_modules\[email protected]@mongodb\lib\operations\mongo_client_ops.js
:439
      throw err;
      ^

TypeError: collection.insert is not a function
    at writeData (F:\nodejs\insertData.js:7:13)
    at F:\nodejs\insertData.js:19:2
    at result (F:\nodejs\node_modules\[email protected]@mongodb\lib\utils.js:414:17
)
    at executeCallback (F:\nodejs\node_modules\[email protected]@mongodb\lib\utils.
js:406:9)
    at err (F:\nodejs\node_modules\[email protected]@mongodb\lib\operations\mongo_c
lient_ops.js:285:5)
    at connectCallback (F:\nodejs\node_modules\[email protected]@mongodb\lib\operat
ions\mongo_client_ops.js:240:5)
    at process.nextTick (F:\nodejs\node_modules\[email protected]@mongodb\lib\opera
tions\mongo_client_ops.js:436:7)
    at process._tickCallback (internal/process/next_tick.js:61:11)

F:\nodejs>node insertData.js
(node:9572) DeprecationWarning: current URL string parser is deprecated, and wil
l be removed in a future version. To use the new parser, pass option { useNewUrl
Parser: true } to MongoClient.connect.
���ӳɹ���
F:\nodejs\node_modules\[email protected]@mongodb\lib\operations\mongo_client_ops.js
:439
      throw err;
      ^

TypeError: collection.insertOne is not a function
    at writeData (F:\nodejs\insertData.js:7:13)
    at F:\nodejs\insertData.js:19:2
    at result (F:\nodejs\node_modules\[email protected]@mongodb\lib\utils.js:414:17
)
    at executeCallback (F:\nodejs\node_modules\[email protected]@mongodb\lib\utils.
js:406:9)
    at err (F:\nodejs\node_modules\[email protected]@mongodb\lib\operations\mongo_c
lient_ops.js:285:5)
    at connectCallback (F:\nodejs\node_modules\[email protected]@mongodb\lib\operat
ions\mongo_client_ops.js:240:5)
    at process.nextTick (F:\nodejs\node_modules\[email protected]@mongodb\lib\opera
tions\mongo_client_ops.js:436:7)
    at process._tickCallback (internal/process/next_tick.js:61:11)

F:\nodejs>node insertData.js
(node:10664) DeprecationWarning: current URL string parser is deprecated, and wi
ll be removed in a future version. To use the new parser, pass option { useNewUr
lParser: true } to MongoClient.connect.
���ӳɹ���
����MongoError: doc parameter must be an object
^C
F:\nodejs>node insertData.js
(node:10308) DeprecationWarning: current URL string parser is deprecated, and wi
ll be removed in a future version. To use the new parser, pass option { useNewUr
lParser: true } to MongoClient.connect.
���ӳɹ���
CommandResult {
  result: { n: 1, ok: 1 },
  connection:
   Connection {
     _events:
      { error: [Function],
        close: [Function],
        timeout: [Function],
        parseError: [Function] },
     _eventsCount: 4,
     _maxListeners: undefined,
     options:
      { host: 'localhost',
        port: 27017,
        size: 5,
        minSize: 0,
        connectionTimeout: 30000,
        socketTimeout: 360000,
        keepAlive: true,
        keepAliveInitialDelay: 300000,
        noDelay: true,
        ssl: false,
        checkServerIdentity: true,
        ca: null,
        crl: null,
        cert: null,
        key: null,
        passPhrase: null,
        rejectUnauthorized: false,
        promoteLongs: true,
        promoteValues: true,
        promoteBuffers: false,
        reconnect: true,
        reconnectInterval: 1000,
        reconnectTries: 30,
        domainsEnabled: false,
        disconnectHandler: [Store],
        cursorFactory: [Function],
        emitError: true,
        monitorCommands: false,
        socketOptions: {},
        promiseLibrary: [Function: Promise],
        clientInfo: [Object],
        read_preference_tags: null,
        readPreference: [ReadPreference],
        dbName: 'student',
        servers: [Array],
        server_options: [Object],
        db_options: [Object],
        rs_options: [Object],
        mongos_options: [Object],
        socketTimeoutMS: 360000,
        connectTimeoutMS: 30000,
        bson: BSON {} },
     id: 0,
     logger: Logger { className: 'Connection' },
     bson: BSON {},
     tag: undefined,
     messageHandler: [Function],
     maxBsonMessageSize: 67108864,
     port: 27017,
     host: 'localhost',
     family: undefined,
     keepAlive: true,
     keepAliveInitialDelay: 300000,
     noDelay: true,
     connectionTimeout: 30000,
     socketTimeout: 360000,
     destroyed: false,
     domainSocket: false,
     singleBufferSerializtion: true,
     serializationFunction: 'toBinUnified',
     ca: null,
     crl: null,
     cert: null,
     key: null,
     passphrase: null,
     ciphers: null,
     ecdhCurve: null,
     ssl: false,
     rejectUnauthorized: false,
     checkServerIdentity: true,
     responseOptions:
      { promoteLongs: true,
        promoteValues: true,
        promoteBuffers: false },
     flushing: false,
     queue: [],
     connection:
      Socket {
        connecting: false,
        _hadError: false,
        _handle: [TCP],
        _parent: null,
        _host: 'localhost',
        _readableState: [ReadableState],
        readable: true,
        _events: [Object],
        _eventsCount: 5,
        _maxListeners: undefined,
        _writableState: [WritableState],
        writable: true,
        allowHalfOpen: false,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: null,
        _server: null,
        timeout: 360000,
        [Symbol(asyncId)]: 15,
        [Symbol(lastWriteQueueSize)]: 0,
        [Symbol(timeout)]: [Timeout],
        [Symbol(kBytesRead)]: 0,
        [Symbol(kBytesWritten)]: 0 },
     writeStream: null,
     hashedName: '29bafad3b32b11dc7ce934204952515ea5984b3c',
     workItems: [],
     buffer: null,
     sizeOfMessage: 0,
     bytesRead: 0,
     stubBuffer: null },
  message:
   Response {
     parsed: true,
     raw:
      <Buffer 3c 00 00 00 f0 02 00 00 02 00 00 00 01 00 00 00 08 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 01 00 00 00 18 00 00 00 10 6e 00 01 00 00 00 01 6f
 6b ... >,
     data:
      <Buffer 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 18 00
00 00 10 6e 00 01 00 00 00 01 6f 6b 00 00 00 00 00 00 00 f0 3f 00>,
     bson: BSON {},
     opts:
      { promoteLongs: true,
        promoteValues: true,
        promoteBuffers: false },
     length: 60,
     requestId: 752,
     responseTo: 2,
     opCode: 1,
     fromCompressed: undefined,
     responseFlags: 8,
     cursorId: Long { _bsontype: 'Long', low_: 0, high_: 0 },
     startingFrom: 0,
     numberReturned: 1,
     documents: [ [Object] ],
     cursorNotFound: false,
     queryFailure: false,
     shardConfigStale: false,
     awaitCapable: true,
     promoteLongs: true,
     promoteValues: true,
     promoteBuffers: false,
     index: 44,
     hashedName: '29bafad3b32b11dc7ce934204952515ea5984b3c' },
  ops:
   [ { name: 'zhangsan', age: '30', _id: 5b70f4bea602b02844490a15 } ],
  insertedCount: 1,
  insertedId: 5b70f4bea602b02844490a15 }

F:\nodejs>

2. Cause of error

In use Node.js When you operate mongodb database and want to insert data records into it, you write a JavaScript file and call the collection function. However, the old version of the method and the new version of the method are not this, but db() instead.

3. Solutions

var MongoClient = require('mongodb').MongoClient;
var DB_URL = 'mongodb://localhost:27017/student';

var writeData = function(db,callback){
	var dbo = db.db('t_sales');
	var data = {'name':'zhangsan','age':'30'};
	dbo.collection('t_sales').insertOne(data,function(error,result){
		if(error){
			console.log('error:'+error);
			return;
		};

		callback(result);
	});
}

MongoClient.connect(DB_URL,function(error,db){
	console.log('connect success!');
	writeData(db,function(result){
		console.log(result);
		db.close();
	});
});