Computer >> 컴퓨터 >  >> 프로그램 작성 >> MongoDB

명령줄로 내 MongoDB 테이블에 연결하는 방법은 무엇입니까?

<시간/>

명령줄로 내 테이블에 연결하려면 db 명령을 사용해야 합니다.

db.yourCollectionName.find();

일부 컬렉션이 포함된 데이터베이스 "샘플"이 있다고 가정해 보겠습니다. 먼저 현재 데이터베이스를 확인하십시오.

> use sample;switched to db sample> db;Sample이제 데이터베이스 샘플에 도달했습니다. 데이터베이스 "샘플"에는 다음 컬렉션이 있습니다.> 컬렉션을 표시합니다.

그러면 다음과 같은 출력이 생성됩니다.

arraySizeErrorDemobasicInformationDemocopyThisCollectionToSampleDatabaseDemodeleteAllRecordsDemodeleteDocumentsdeleteDocumentsDemodeleteSomeInformationdocumentWithAParticularFieldValueDemoemployeefindListOfIdsDemofindSubstringgetAllRecordsFromSourceCollectionDemogetElementWithMaxIdDemointernalArraySizeDemolargestDocumentDemomakingStudentInformationCloneoppositeAddToSetDemoprettyDemoreturnOnlyUniqueValuesDemoselectWhereInDemosourceCollectionstudentInformationsumOfValueDemosumTwoFieldsDemotruncateDemoupdateInformationuserInformation

다음은 테이블, 즉 컬렉션에 연결하는 올바른 방법입니다. db 명령을 사용해야 합니다. 다음은 쿼리입니다.

> db.userInformation.find();

그러면 다음과 같은 출력이 생성됩니다.

{ "_id" :ObjectId("5c6a765964f3d70fcc9147f5"), "Name" :"John", "Age" :30, "isStudent" :false, "Subjects" :[ "Java 소개", "MongoDB 소개 " ] }