MongoDB常用的操作(数据库、集合)

MongoDB常用命令大全 一、数据库相关 1.连接 (1)完整 mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]] (2)使用默认端口 mongodb://localhost (3)使用shell mongo 2.查询数据库 (1)查询所有数据库 show dbs 3.创建数据库 use database_name 如果数据库不存在,则创 阅读详情
AI摘要

本文详细介绍了MongoDB的启动与管理方法,包括启动命令、检查服务状态、数据库创建、查询、删除以及数据集合的操作,如创建集合并设置配置选项。

MongoDB常用操作

一、MongoDB启动命令

1.启动MongoDB:

systemctl start mongod

2.查看是否启动成功:

systemctl status mongod

3.重启MongoDB:

systemctl restart mongod

4.关闭MongoDB:

systemctl stop mongod

二、启动MongoDB客户端

1.查看服务是否启动:

ps -def | grep mongod

2.查看服务器是否正确:

cd /data/db/journal/
cat mongodb.log

3.查看服务器是否启动正常:

http://127.0.0.1:28017

4.查看是否能够正常登录:

进入/usr/mongodb/bin,执行./mongo

三、MongoDB数据库操作

1.创建数据库:

use DATABASE_NAME

如果数据库不存在,则创建数据库,否则切换到指定数据库

2.查询当前所在数据库:

db

3.查看所有数据库:

show dbs /show databases

4.删除当前所在数据库:

db.dropDatabase()

四、MongoDB操作数据集合

创建集合:

db.createCollection(collectionName,option)

其中,name是集合的名称,option是集合的配置选项。option参数是可选的,可以使用以下参数:

字段类型描述
cappedBoolean如果为true,则启用封闭的集合,上限是固定大小的集合,在到达最大大小时自动覆盖最旧的条目。如果指定为true。则还需指定size参数。
autolndexldBoolean如果为true,则在_id列自动创建索引。
size数字指定上限集合的最大尺寸(以字节为单位),与capped配合使用。
max数字 指定上限集合中允许的最大文档数。

数据库MongoDB启动方式(3种) - 方法总结篇 MongoDB启动方式(3种方法,环环相扣),分别从低级到高级,罗列如下: Method 1. 最原始的启动方式:cmd + cd到安装路径 cmd命令行cd到安装路径: cd C:\Program Files\MongoDB\Server\3.4\bin 然后cmd启动MongoDB,执行cmd命令: mongod.exe --dbpath E:\db\MongoDB Metho... 阅读详情

相关推荐

MongoDB启动命令及编程示例

启动MongoDB需要执行一条特定的命令,本文将介绍MongoDB的启动命令以及提供一个编程示例。通过启动命令,我们可以启动MongoDB服务器并配置相应的参数。请注意,上述示例仅展示了MongoDB的连接和关闭过程,并没有包含具体的数据库操作。在启动MongoDB之前,我们需要确保MongoDB已经正确安装并配置好了环境变量。MongoDB提供了多种编程语言的驱动程序,这里我们以Node.js为例,使用官方提供的。是可选的命令行选项,用于配置MongoDB的各种参数。方法关闭与MongoDB的连接。

ByteNinja的博客 851

MongoDB常用的操作(服务器、数据库、集合)

前面两篇已经介绍了MongoDB系统架构及其BSON数据类型。本文将讲解基本的MongoDB操作。

记录总结工作过往 3501

02 MongoDB数据类型、重要概念以及shell常用指令

类似唯一主键,可以很快的去生成和排序,包含 12 bytes,含义是:: BSON 字符串都是 UTF-8 编码。: BSON 时间戳类型主要用于 MongoDB 内部使用。在大多数情况下的应用开发中,可以使用 BSON 日期类型。: 表示当前距离 Unix新纪元(1970年1月1日)的毫秒数。日期类型是有符号的, 负数表示 1970 年之前的日期。有一些数据库名是保留的,可以直接访问这些有特殊作用的数据库。文档是一组键值(key-value)对(即 BSON)。MongoDB 的文档不需要设置相同的字

数据知道的博客 3万+

MongoDB的常用命令(数据库操作、集合操作、文档操作)

MongoDB的常用命令(数据库操作、集合操作、文档操作)

聂可以的博客 8030

从SAR信号到洪涝地图:基于Sentinel-1数据的水体快速提取实战

本文详细介绍了如何利用Sentinel-1 SAR数据快速提取水体信息并生成洪涝地图的实战方法。通过预处理五部曲和SDWI指数计算,结合具体案例展示了SAR技术在洪涝灾害应急监测中的高效性和准确性,为救援决策提供关键支持。

weixin_29201313的博客 483

Mac用户必看:Parallels Desktop 18.1.1最新破解版安装与优化全攻略(附资源)

本文为Mac用户提供Parallels Desktop 18.1.1的详细安装与优化指南,涵盖虚拟化技术选型、专业级配置流程及性能调优技巧。重点解析Parallels Desktop在图形加速、系统资源调度方面的核心优势,并分享生产力增强技巧与典型应用场景实战方案,帮助用户最大化利用这一高效虚拟化工具。

weixin_29240343的博客 864

#NodeJS# MongoDB常用数据库操作之创建集合、文档

mongodb不需要显示创建数据库,如果数据库不存在,它会自动创建。 创建集合 const Schema = new mongoose.Schema(options) //创建集合结构(规则) options集 合的结构(规则) const Model = mongoose.model(modelName, schema) //modalName集合名称 schema集合结构 //案例例代码 ...

自学it的攻城狮 858

基于睿抗智能小车省赛第一题兵人识别的学习5.25

先用pip uninstall numpy卸载,再在后面输入pip install numpy==1.23安装版本为1.23的numpy。首先安装Anaconda环境;pycharm方便使用,安装yolov5以及一大堆数据包;由于python中的numpy插件包版本过高,训练失败,所以要安装一个版本低的包。每次运行都要先运行虚拟环境,输入:conda activate。图中所有精度大概在0.768-0.99之间。这里指定安装numpy1.23.。训练完成会得到一个衡量精度的指标。等待99张图片训练完成。

Haili_的博客 1307

MongoDB教程001:基本常用命令(数据库操作和集合操作)

注意:在MongoDB中,集合只有在内容插入后才会创建。就是说,创建集合(数据表)后要插入一个文档(记录),集合才会真正创建。有一些数据库名是保留的,可以直接访问这些特殊作用的数据库。数据库名可以是满足以下条件的任意UTF-8字符串。如果数据库不存在则自动创建,例如,以下语句创建。提示:主要用来删除已经持久化的数据库。,如果你没有选择数据库,集合将存放在。可以显示的创建,也可以隐式的创建。查看有权限查看的所有数据库命令。MongoDB中默认的数据库为。存放文章评论的数据存放到。

WwLK123的博客 864

NX二次开发编译时dll自动数字签名及拷贝

在UG5.0开始,所有基于UG二次开发的DLL都要“签名”后才能被客户端上正版的NX调用。

菜鸟爱飞不飞的博客 2696

亿图图示(edrawmax中文版) v10.1.7pjb

edrawmax中文名叫做亿图图示,是一款非常棒的综合图形图表设计软件,既能实现流程图、架构图、工程图、思维导图等数百种专业领域图形图表的绘制,又能提供一个白板进行头脑风暴和任意编排,轻松实现数据和创意的可视化呈现。软件支持Windows、Mac、Linux及网络版,一端创作,多端同步,从而为跨端办公绘图提供新的解决方案,还兼容常用文档类的办公软件格式,包括图片、Office、PDF、Visio、Html、SVG等,尽可能的在文件格式这块满足用户多方面需求。软件支持创建260多种图表类型,拥有超过12500

qq_43293214的博客 1万+

MongoDB Shell(mongosh)中常用的操作指令,涵盖数据库、集合、文档的增删改查等核心操作

示例:将所有 role 为 user 的用户添加 active: true db.users.updateMany( { role: "user" }, { $set: { active: true } } )# 示例:将 name 为 Alice 的用户年龄改为 31 db.users.updateOne( { name: "Alice" }, { $set: { age: 31 } } )# 示例:按年龄降序排序 db.users.find().sort({ age: -1 })

m0_73585771的博客 1420

pcle接口详解&用途说明

它原来的名称为“3GIO”,由英特尔在2001年提出。pcel x16插槽 用途用于显卡、RAID阵列卡,向下兼容PCIE x1/x4/x8/x16。(PCIE x16插槽长89mm,有164根针脚,靠主板外侧端有一卡口,将16x分为前后两组,短插槽有22根针脚,主要用于供电,长插槽142根,主要用于数据传输,具有16通道所带来的高带宽)PCI-E x8插槽插槽用途:全长56mm,有98根针脚,与PCI-E x16比较,主要是数据针脚减少至76根,短的供电针脚仍然是22针脚。

qq_43289307的博客 1万+

【MongoDB学习笔记1】MongoDB的常用命令介绍-数据库操作、集合操作、文档操作、文档分页查询、高级查询

MongoDB中默认的数据库为test,如果没有选择数据库,集合将会存放在test数据库中。选择和创建数据库,如果数据库存在则使用这个数据库,如果数据库不存在则自动创建在MongoDB中,集合只有在内容插入后才会创建,就是说,创建集合后要再插入一个文档(记录),集合才会真正创建。创建了库,但是系统中没有显示,因为先创建的库只保存在内存中,当创建集合后,系统会自动将新创建的库持久化,这时候才能查看到库有些数据库名是保留的,可以直接访问这些有特殊作用的数据库主要用来删除已经持久化的数据库。

大龄IT民工 1174

YOLOv8目标出入计数部署:讲解C#使用ONNX检测模型进行目标出入计数 可运行完整实例

代码、步骤、讲解完整,可一键运行,效果如下:车辆出入计数人员出入计数。

Limiiiing的博客 89

滑块逆向及流程分析

本文章中所有内容仅供学习交流使用,不用于其他任何目的,不提供完整代码,抓包内容、敏感网址、数据接口等均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后果均与作者无关!

pyzzd的博客 8021

MongoDB基本操作语句

1、连接 ./mongo ip:port use admin db.auth("admin","password") 2、创建(切换)数据库 MongoDB 创建数据库的语法格式如下: use DATABASE_NAME 如果数据库不存在,则创建数据库,否则切换到指定数据库。 #以下实例我们创建了数据库 testdb mongos> use testdb switched to ...

weixin_38932035的博客 1163

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

MongoDb

MongoDb 什么是mongodb? MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。 MongoDB 将数据存储为一个文档,数据结构由键值(key=>value)对组成。 ...

dawei.tu的博客 339

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

MongoDB—— shell常用命令

一、mongo shell常用命令 命令 说明 show dbs或者show databases 显示数据库列表 use 数据库名 切换数据库,如果不存在创建数据库 db.dropDatabase() 删除数据库 show collections或者show tables 显示当前数据库的集合列表 db.集合名.stats() 查看集合详情 db.集合名.drop() 删除集合 show users 显示当前数据库的用户列表 show roles 显示当前数据库的

小志的博客 2608

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

MongoDB在不同主机间复制数据库和集合的教程_MongoDB_脚本之家

MongoDB在不同主机间复制数据库和集合的教程 更新时间:2016年07月04日 15:49:51 作者:lucifercn MongoDB自带了clone一族JavaScript函数来进行数据的复制,这里我们总结了MongoDB在不同主机间复制数据库和集合的教程,列举出了一些主从复制操作中常用的重要函数: 1. db.cloneCollection() db.cloneCollection(from, collection, query) 在不同的mongodb实例间复制数据,db.cl...

没做过产品的后端不是个好前端 429

MongoDB 数据库_集合_文档 常用命令行操作

目录 MongoDB 常用操作 数据库与集合操作 文档操作 向集合添加文档 删除集合中文档 查询集合中文档 更新集合中文档 本文导读 本文承接《MongoDB 下载_安装_配置 及 启动与连接》,启动 MongoDB 与 连接 MongoDB 了解之后,现在来掌握 MongoDB 的操作语法。 MongoDB 常用操作 命令 作用 举例 mongod--db...

蚩尤后裔-汪茂雄 1852

3、MongoDB数据库集合常用操作

1、MongoDB数据库里面的集合,相当于关系型数据库的表 2、集合的显示创建 db.createCollection("c1"); 3、集合的隐式创建(直接在创建集合的同时往集合里添加数据(直接创建c2集合,并添加数据)) db.c2.insert( { id:"1",name:"zhejiang" } ); 4、查看集合里面的文档数量 db.c2.find(

Learning 576

MongoDB学习笔记

#创建数据库 use 数据库名称 #数据库不存在创建,存在切换到当前数据库 db.集合名称.insert({"name":"插入测试文档"}) #删除数据库 db.dropDatabase()#删除当前数据库 #查看数据库 show dbs #查看当前数据库的名称 db #创建集合 db.createCollection() #集合相当于sql中的表 #查看当前数据库...

weixin_30765577的博客 82

mongodb学习(2)

mongodb的命令 对数据库操作 //查看当前数据库 db //查看所有数据库(如果数据库里面没有任何集合,不显示) show dbs //切换到已存在的库(若不存在,则创建),name是数据库名 use name //查看当前数据库 db.getName() //当前数据库状态 db.stats() //查看当前数据库的连接 db.getMongo() //删除当前数据库 db.dropDatabase() //查看当前数据库的js原型 db.xxx.insert ...

worthyyyou的博客 172

MongoDB常用操作命令大全

成功启动MongoDB后,再打开一个命令行窗口输入mongo,就可以进行数据库的一些操作。输入help可以看到基本操作命令,只是MongoDB没有创建数据库的命令,但有类似的命令   如:如果你想创建一个“myTest”的数据库,先运行use myTest命令,之后就做一些操作(如:db.createCollection('user')),这样就可以创建一个名叫“myTest”的数据库。

雅冰石的专栏 741
上一篇: MongoDB副本集部署(Windows)
下一篇: MongoDB分片集群部署
Meguling
博客等级 码龄3年 70粉丝 10原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址