- 전체
- Sample DB
- database modeling
- [표준 SQL] Standard SQL
- G-SQL
- 10-Min
- ORACLE
- MS SQLserver
- MySQL
- SQLite
- postgreSQL
- 데이터아키텍처전문가 - 국가공인자격
- 데이터 분석 전문가 [ADP]
- [국가공인] SQL 개발자/전문가
- NoSQL
- hadoop
- hadoop eco system
- big data (빅데이터)
- stat(통계) R 언어
- XML DB & XQuery
- spark
- DataBase Tool
- 데이터분석 & 데이터사이언스
- Engineer Quality Management
- [기계학습] machine learning
- 데이터 수집 및 전처리
- 국가기술자격 빅데이터분석기사
- 암호화폐 (비트코인, cryptocurrency, bitcoin)
NoSQL [mongodb] Get substring in MongoDB aggregate
2020.12.04 14:56
[mongodb] Get substring in MongoDB aggregate
To get substring, use $substr in MongoDB. Let us create a collection with documents −
> db.demo176.insertOne({"ProductName":"PRODUCT-1"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3843a09e4f06af551997ef") } > db.demo176.insertOne({"ProductName":"PRODUCT-102"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3843a69e4f06af551997f0") } > db.demo176.insertOne({"ProductName":"PRODUCT-105"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3843aa9e4f06af551997f1") }
Display all documents from a collection with the help of find() method −
> db.demo176.find();
This will produce the following output −
{ "_id" : ObjectId("5e3843a09e4f06af551997ef"), "ProductName" : "PRODUCT-1" }
{ "_id" : ObjectId("5e3843a69e4f06af551997f0"), "ProductName" : "PRODUCT-102" }
{ "_id" : ObjectId("5e3843aa9e4f06af551997f1"), "ProductName" : "PRODUCT-105" }
Following is the query to get substring in MongoDB aggregate −
> db.demo176.aggregate( ... [ ... { ... $project: ... { ... ... ProductName: { $substr: [ "$ProductName", 0, 7] } ... ... } ... } ... ] ...)
This will produce the following output −
{ "_id" : ObjectId("5e3843a09e4f06af551997ef"), "ProductName" : "PRODUCT" }
{ "_id" : ObjectId("5e3843a69e4f06af551997f0"), "ProductName" : "PRODUCT" }
{ "_id" : ObjectId("5e3843aa9e4f06af551997f1"), "ProductName" : "PRODUCT" }
[출처] https://www.tutorialspoint.com/get-substring-in-mongodb-aggregate
본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.

