Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The realization method of data Type conversion by using mongoshell in Mongodb

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

$type operator

Detection type

Category code alias

Double 1 "double"

String 2 "string"

Object 3 "object"

Array 4 "array"

Binary data 5 "binData"

Undefined 6 "undefined" Deprecated.

ObjectId 7 "objectId"

Boolean 8 "bool"

Date 9 "date"

Null 10 "null"

Regular Expression 11 "regex"

DBPointer 12 "dbPointer"

JavaScript 13 "javascript"

Symbol 14 "symbol"

JavaScript (with scope) 15 "javascriptWithScope"

32-bit integer 16 "int"

Timestamp 17 "timestamp"

64-bit integer 18 "long"

Min key-1 "minKey"

Max key 127 "maxKey

Db.article.find ({data: {$type:2}) / / find a document whose data field is string

ForEach function

Use the js function for each document in the query result collection

Cursor.forEach (function) Iterates the cursor to apply a JavaScript function to each document from the cursor.

Use examples

Convert the string in the data.tagList array to int32,x representing the iterated incoming document

Db.article.find ({"data.tagList.0": {$type:2}}) .forEach (function (x) {var iTuno / var length=x.data.tagList.length; for

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report