Hướng dẫn javascript object id - id đối tượng javascript

Phương thức

import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
2 cung cấp cho bạn chuỗi HEX là loại mã ASCII nhưng trong hệ thống số 16 cơ sở.

Chuyển đổi ID thành chuỗi hex 24 ký tự để in

Ví dụ: trong hệ thống này:

"a" -> 61
"b" -> 62
"c" -> 63

Vì vậy, nếu bạn vượt qua

import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
3 để nhận
import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
4, bạn sẽ nhận được "616263 ...".

Kết quả là nếu bạn muốn nhận chuỗi có thể đọc được (chuỗi char) từ

import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
4, bạn phải chuyển đổi nó (HexCode thành char).

Để làm điều này, tôi đã viết một chức năng tiện ích

import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
6
function hexStringToCharString(hexString) {
  const hexCodeArray = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray = hexCodeArray.map((hex) => parseInt(hex, 16));

  return String.fromCharCode(...decimalCodeArray);
}

Và có việc sử dụng chức năng

import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001

Và cũng có phiên bản TypeScript của HexStringToCharString () hàmTypeScript version of hexStringToCharString() functionTypeScript version of hexStringToCharString() function

function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}

Truy vấn MongoDB để loại bỏ mục khỏi mảng?

Truy vấn MongoDB để loại bỏ Subdocument khỏi tài liệu?

Phương thức

import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
2 cung cấp cho bạn chuỗi HEX là loại mã ASCII nhưng trong hệ thống số 16 cơ sở.
"a" -> 61
"b" -> 62
"c" -> 63

Chuyển đổi ID thành chuỗi hex 24 ký tự để in

Ví dụ: trong hệ thống này:

Vì vậy, nếu bạn vượt qua

import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
3 để nhận
import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
4, bạn sẽ nhận được "616263 ...".

Kết quả là nếu bạn muốn nhận chuỗi có thể đọc được (chuỗi char) từ

import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
4, bạn phải chuyển đổi nó (HexCode thành char).

Để làm điều này, tôi đã viết một chức năng tiện ích

Và có việc sử dụng chức năngTypeScript version of hexStringToCharString() function
function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}

Và cũng có phiên bản TypeScript của HexStringToCharString () hàmTypeScript version of hexStringToCharString() functionMongoDB Manual

function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
2

Truy vấn MongoDB để loại bỏ mục khỏi mảng?

function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
3.

Truy vấn MongoDB để loại bỏ Subdocument khỏi tài liệu?

  • import { ObjectId } from "mongodb";
    
    const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
    const myObjectId = new ObjectId(myId); // create ObjectId from string
    
    console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
    console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031
    
    const convertedFromToHexString = hexStringToCharString(
      myObjectId.toHexString(),
    );
    
    const convertedFromToString = hexStringToCharString(myObjectId.toString());
    
    console.log(`convertedFromToHexString:`, convertedFromToHexString);
    //convertedFromToHexString: user-0000001
    console.log(`convertedFromToString:`, convertedFromToString);
    //convertedFromToHexString: user-0000001
    
    2 cung cấp cho bạn chuỗi HEX là loại mã ASCII nhưng trong hệ thống số 16 cơ sở.
    "a" -> 61
    "b" -> 62
    "c" -> 63
    

    import { ObjectId } from "mongodb";
    
    const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
    const myObjectId = new ObjectId(myId); // create ObjectId from string
    
    console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
    console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031
    
    const convertedFromToHexString = hexStringToCharString(
      myObjectId.toHexString(),
    );
    
    const convertedFromToString = hexStringToCharString(myObjectId.toString());
    
    console.log(`convertedFromToHexString:`, convertedFromToHexString);
    //convertedFromToHexString: user-0000001
    console.log(`convertedFromToString:`, convertedFromToString);
    //convertedFromToHexString: user-0000001
    
    3 để nhận
    import { ObjectId } from "mongodb";
    
    const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
    const myObjectId = new ObjectId(myId); // create ObjectId from string
    
    console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
    console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031
    
    const convertedFromToHexString = hexStringToCharString(
      myObjectId.toHexString(),
    );
    
    const convertedFromToString = hexStringToCharString(myObjectId.toString());
    
    console.log(`convertedFromToHexString:`, convertedFromToHexString);
    //convertedFromToHexString: user-0000001
    console.log(`convertedFromToString:`, convertedFromToString);
    //convertedFromToHexString: user-0000001
    
    4, bạn sẽ nhận được 616263.
    "a" -> 61
    "b" -> 62
    "c" -> 63
    
    3
  • import { ObjectId } from "mongodb";
    
    const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
    const myObjectId = new ObjectId(myId); // create ObjectId from string
    
    console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
    console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031
    
    const convertedFromToHexString = hexStringToCharString(
      myObjectId.toHexString(),
    );
    
    const convertedFromToString = hexStringToCharString(myObjectId.toString());
    
    console.log(`convertedFromToHexString:`, convertedFromToHexString);
    //convertedFromToHexString: user-0000001
    console.log(`convertedFromToString:`, convertedFromToString);
    //convertedFromToHexString: user-0000001
    
    4, bạn phải chuyển đổi nó (HexCode thành char).
    import { ObjectId } from "mongodb";
    
    const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
    const myObjectId = new ObjectId(myId); // create ObjectId from string
    
    console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
    console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031
    
    const convertedFromToHexString = hexStringToCharString(
      myObjectId.toHexString(),
    );
    
    const convertedFromToString = hexStringToCharString(myObjectId.toString());
    
    console.log(`convertedFromToHexString:`, convertedFromToHexString);
    //convertedFromToHexString: user-0000001
    console.log(`convertedFromToString:`, convertedFromToString);
    //convertedFromToHexString: user-0000001
    

    import { ObjectId } from "mongodb";
    
    const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
    const myObjectId = new ObjectId(myId); // create ObjectId from string
    
    console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
    console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031
    
    const convertedFromToHexString = hexStringToCharString(
      myObjectId.toHexString(),
    );
    
    const convertedFromToString = hexStringToCharString(myObjectId.toString());
    
    console.log(`convertedFromToHexString:`, convertedFromToHexString);
    //convertedFromToHexString: user-0000001
    console.log(`convertedFromToString:`, convertedFromToString);
    //convertedFromToHexString: user-0000001
    
    6TypeScript version of hexStringToCharString() function
    function hexStringToCharString(hexString: string): string {
      const hexCodeArray: string[] = [];
    
      for (let i = 0; i < hexString.length - 1; i += 2) {
        hexCodeArray.push(hexString.slice(i, i + 2));
      }
    
      const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
        parseInt(hex, 16),
      );
    
      return String.fromCharCode(...decimalCodeArray);
    }
    
    import { ObjectId } from "mongodb";
    
    const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
    const myObjectId = new ObjectId(myId); // create ObjectId from string
    
    console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
    console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031
    
    const convertedFromToHexString = hexStringToCharString(
      myObjectId.toHexString(),
    );
    
    const convertedFromToString = hexStringToCharString(myObjectId.toString());
    
    console.log(`convertedFromToHexString:`, convertedFromToHexString);
    //convertedFromToHexString: user-0000001
    console.log(`convertedFromToString:`, convertedFromToString);
    //convertedFromToHexString: user-0000001
    
    2
    method.
  • Tài liệu về nhà → Hướng dẫn sử dụng MongoDB → MongoDB Manual

    function hexStringToCharString(hexString: string): string {
      const hexCodeArray: string[] = [];
    
      for (let i = 0; i < hexString.length - 1; i += 2) {
        hexCodeArray.push(hexString.slice(i, i + 2));
      }
    
      const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
        parseInt(hex, 16),
      );
    
      return String.fromCharCode(...decimalCodeArray);
    }
    
    8.

Trả về biểu diễn chuỗi của

function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
9:
function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
9:
import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
8
function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
9
:
import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
8

Ví dụ sau:

Tạo một

function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
3 mới và lưu trữ nó trong biến
function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
5.

Tạo một biểu diễn chuỗi của

Và cũng có phiên bản TypeScript của HexStringToCharString () hàmTypeScript version of hexStringToCharString() functionMongoDB Manual

Truy vấn MongoDB để loại bỏ mục khỏi mảng?

Truy vấn MongoDB để loại bỏ Subdocument khỏi tài liệu?
  • Truy vấn MongoDB để loại bỏ Subdocument khỏi tài liệu?
"a" -> 61
"b" -> 62
"c" -> 63
2

import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
2 cung cấp cho bạn chuỗi HEX là loại mã ASCII nhưng trong hệ thống số 16 cơ sở.
"a" -> 61
"b" -> 62
"c" -> 63

import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
3 để nhận
import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
4, bạn sẽ nhận được 616263.
"a" -> 61
"b" -> 62
"c" -> 63
3

Truy vấn MongoDB để loại bỏ Subdocument khỏi tài liệu?

import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
2 cung cấp cho bạn chuỗi HEX là loại mã ASCII nhưng trong hệ thống số 16 cơ sở.
"a" -> 61
"b" -> 62
"c" -> 63

import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
3 để nhận
import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
4, bạn sẽ nhận được 616263.
"a" -> 61
"b" -> 62
"c" -> 63
3
"a" -> 61
"b" -> 62
"c" -> 63
6
method on an
function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
3:
import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
9

import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
4, bạn phải chuyển đổi nó (HexCode thành char).
import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001

import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
6TypeScript version of hexStringToCharString() function
function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}

Tài liệu về nhà → Hướng dẫn sử dụng MongoDB → MongoDB Manual

function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
8.
function hexStringToCharString(hexString) {
  const hexCodeArray = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray = hexCodeArray.map((hex) => parseInt(hex, 16));

  return String.fromCharCode(...decimalCodeArray);
}
1

Trả về biểu diễn chuỗi của

Ví dụ sau:ObjectId.toString()UUID() →

Ví dụ sau:

Tạo một

function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
3 mới và lưu trữ nó trong biến
function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
5.

Tạo một biểu diễn chuỗi của

"a" -> 61
"b" -> 62
"c" -> 63

function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
5 bằng phương pháp
import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
2.
import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
2 method.

Lưu trữ biểu diễn chuỗi trong biến

Chạy các lệnh sau trong

Hoạt động trả về chuỗi sau:

Để xác nhận loại

function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
8, hãy sử dụng toán tử JavaScript
"a" -> 61
"b" -> 62
"c" -> 63
1:

Hoạt động trả về như sau:TypeScript version of hexStringToCharString() function

function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}

function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
3.

function hexStringToCharString(hexString) {
  const hexCodeArray = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray = hexCodeArray.map((hex) => parseInt(hex, 16));

  return String.fromCharCode(...decimalCodeArray);
}
6

function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
3 mới và lưu trữ nó trong biến
function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
5.
"a" -> 61
"b" -> 62
"c" -> 63
6 method on an
function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
3:
import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
9

function hexStringToCharString(hexString) {
  const hexCodeArray = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray = hexCodeArray.map((hex) => parseInt(hex, 16));

  return String.fromCharCode(...decimalCodeArray);
}
7

Phương thức

function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
5 bằng phương pháp
import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
2.
function hexStringToCharString(hexString) {
  const hexCodeArray = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray = hexCodeArray.map((hex) => parseInt(hex, 16));

  return String.fromCharCode(...decimalCodeArray);
}
0

Chuyển đổi ID thành chuỗi hex 24 ký tự để in

function hexStringToCharString(hexString) {
  const hexCodeArray = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray = hexCodeArray.map((hex) => parseInt(hex, 16));

  return String.fromCharCode(...decimalCodeArray);
}
9

Ví dụ: trong hệ thống này:

import { ObjectId } from "mongodb";

const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
const myObjectId = new ObjectId(myId); // create ObjectId from string

console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031

const convertedFromToHexString = hexStringToCharString(
  myObjectId.toHexString(),
);

const convertedFromToString = hexStringToCharString(myObjectId.toString());

console.log(`convertedFromToHexString:`, convertedFromToHexString);
//convertedFromToHexString: user-0000001
console.log(`convertedFromToString:`, convertedFromToString);
//convertedFromToHexString: user-0000001
0

Phương thức

function hexStringToCharString(hexString: string): string {
  const hexCodeArray: string[] = [];

  for (let i = 0; i < hexString.length - 1; i += 2) {
    hexCodeArray.push(hexString.slice(i, i + 2));
  }

  const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
    parseInt(hex, 16),
  );

  return String.fromCharCode(...decimalCodeArray);
}
9:ObjectId.toString()UUID() →

Trên trang này

  • Thí dụ
  • Trả về giá trị của
  • function hexStringToCharString(hexString: string): string {
      const hexCodeArray: string[] = [];
    
      for (let i = 0; i < hexString.length - 1; i += 2) {
        hexCodeArray.push(hexString.slice(i, i + 2));
      }
    
      const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
        parseInt(hex, 16),
      );
    
      return String.fromCharCode(...decimalCodeArray);
    }
    
    3 dưới dạng chuỗi thập lục phân chữ thường. Giá trị này là thuộc tính
    "a" -> 61
    "b" -> 62
    "c" -> 63
    
    4 của đối tượng
    function hexStringToCharString(hexString: string): string {
      const hexCodeArray: string[] = [];
    
      for (let i = 0; i < hexString.length - 1; i += 2) {
        hexCodeArray.push(hexString.slice(i, i + 2));
      }
    
      const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
        parseInt(hex, 16),
      );
    
      return String.fromCharCode(...decimalCodeArray);
    }
    
    3.
    function hexStringToCharString(hexString) {
      const hexCodeArray = [];
    
      for (let i = 0; i < hexString.length - 1; i += 2) {
        hexCodeArray.push(hexString.slice(i, i + 2));
      }
    
      const decimalCodeArray = hexCodeArray.map((hex) => parseInt(hex, 16));
    
      return String.fromCharCode(...decimalCodeArray);
    }
    
  • Ví dụ sau đây gọi phương thức
  • "a" -> 61
    "b" -> 62
    "c" -> 63
    
    6 trên
    function hexStringToCharString(hexString: string): string {
      const hexCodeArray: string[] = [];
    
      for (let i = 0; i < hexString.length - 1; i += 2) {
        hexCodeArray.push(hexString.slice(i, i + 2));
      }
    
      const decimalCodeArray: number[] = hexCodeArray.map((hex) =>
        parseInt(hex, 16),
      );
    
      return String.fromCharCode(...decimalCodeArray);
    }
    
    3:
    import { ObjectId } from "mongodb";
    
    const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
    const myObjectId = new ObjectId(myId); // create ObjectId from string
    
    console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
    console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031
    
    const convertedFromToHexString = hexStringToCharString(
      myObjectId.toHexString(),
    );
    
    const convertedFromToString = hexStringToCharString(myObjectId.toString());
    
    console.log(`convertedFromToHexString:`, convertedFromToHexString);
    //convertedFromToHexString: user-0000001
    console.log(`convertedFromToString:`, convertedFromToString);
    //convertedFromToHexString: user-0000001
    
  • Điều này sẽ trả về chuỗi sau:TypeScript version of hexStringToCharString() function
  • Bạn có thể xác nhận loại đối tượng này bằng cách sử dụng thao tác sau:
  • ← & nbsp; objectid.toString () uuid () & nbsp; →
  • import { ObjectId } from "mongodb";
    
    const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
    const myObjectId = new ObjectId(myId); // create ObjectId from string
    
    console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
    console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031
    
    const convertedFromToHexString = hexStringToCharString(
      myObjectId.toHexString(),
    );
    
    const convertedFromToString = hexStringToCharString(myObjectId.toString());
    
    console.log(`convertedFromToHexString:`, convertedFromToHexString);
    //convertedFromToHexString: user-0000001
    console.log(`convertedFromToString:`, convertedFromToString);
    //convertedFromToHexString: user-0000001
    
    2 cung cấp cho bạn chuỗi HEX là loại mã ASCII nhưng trong hệ thống số 16 cơ sở.
    function hexStringToCharString(hexString) {
      const hexCodeArray = [];
    
      for (let i = 0; i < hexString.length - 1; i += 2) {
        hexCodeArray.push(hexString.slice(i, i + 2));
      }
    
      const decimalCodeArray = hexCodeArray.map((hex) => parseInt(hex, 16));
    
      return String.fromCharCode(...decimalCodeArray);
    }
    
    8
  • import { ObjectId } from "mongodb";
    
    const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
    const myObjectId = new ObjectId(myId); // create ObjectId from string
    
    console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
    console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031
    
    const convertedFromToHexString = hexStringToCharString(
      myObjectId.toHexString(),
    );
    
    const convertedFromToString = hexStringToCharString(myObjectId.toString());
    
    console.log(`convertedFromToHexString:`, convertedFromToHexString);
    //convertedFromToHexString: user-0000001
    console.log(`convertedFromToString:`, convertedFromToString);
    //convertedFromToHexString: user-0000001
    
    2 cung cấp cho bạn chuỗi HEX là loại mã ASCII nhưng trong hệ thống số 16 cơ sở.
    import { ObjectId } from "mongodb";
    
    const myId = "user-0000001"; // must contains 12 character for "mongodb": 4.3.0
    const myObjectId = new ObjectId(myId); // create ObjectId from string
    
    console.log(myObjectId.toString()); // hex string >> 757365722d30303030303031
    console.log(myObjectId.toHexString()); // hex string >> 757365722d30303030303031
    
    const convertedFromToHexString = hexStringToCharString(
      myObjectId.toHexString(),
    );
    
    const convertedFromToString = hexStringToCharString(myObjectId.toString());
    
    console.log(`convertedFromToHexString:`, convertedFromToHexString);
    //convertedFromToHexString: user-0000001
    console.log(`convertedFromToString:`, convertedFromToString);
    //convertedFromToHexString: user-0000001
    
    1
  • Cập nhật vào ngày 03 tháng 4 năm 2020 12:31:37
  • Câu hỏi và câu trả lời liên quan
  • Chuyển đổi chuỗi thành ObjectID trong MongoDB?
  • Cách chuyển đổi ObjectID thành chuỗi trong MongoDB
  • Truy vấn MongoDB để loại bỏ mục khỏi mảng?
  • Truy vấn MongoDB để loại bỏ Subdocument khỏi tài liệu?