Home Php C# Sql C C++ Javascript Python Java Go Android Git Linux Asp.net Django .net Node.js Ios Xcode Cocoa Iphone Mysql Tomcat Mongodb Bash Objective-c Scala Visual-studio Apache Elasticsearch Jar Eclipse Jquery Ruby-on-rails Ruby Rubygems Android-studio Spring Lua Sqlite Emacs Ubuntu Perl Docker Swift Amazon-web-services Svn Html Ajax Xml Java-ee Maven Intellij-idea Rvm Macos Unix Css Ipad Postgresql Css3 Json Windows-server Vue.js Typescript Oracle Hibernate Internet-explorer Github Tensorflow Laravel Symfony Redis Html5 Google-app-engine Nginx Firefox Sqlalchemy Lucene Erlang Flask Vim Solr Webview Facebook Zend-framework Virtualenv Nosql Ide Twitter Safari Flutter Bundle Phonegap Centos Sphinx Actionscript Tornado Register | Login | Edit Tags | New Questions | 繁体 | 简体


10 questions online user: 9

0
votes
answers
47 views
+10

貓鼬填充不是爲我工作

0

我有這個架構用戶貓鼬填充不是爲我工作

var mongoose = require("mongoose"), 
    passportLocalMongoose = require("passport-local-mongoose"); 

mongoose.Promise = global.Promise; 

var userSchema = new mongoose.Schema ({ 
    username: {type: String, required: true, unique: true}, 
    password: {type: String}, 
    role: {type: String, required: true}, 
    confirmed: {type: Boolean, required: true, default: false}, 
    active: {type: Boolean, required: true, default: true}, 
    name: String, 
    created: {type: Date, default: Date.now}, 
    admin: {type: Boolean, default: false, required: true} 
}); 

userSchema.plugin(passportLocalMongoose); 

module.exports = mongoose.model("User", userSchema); 

而另一架構公司,其中客戶用戶數組:

var mongoose = require("mongoose"); 
mongoose.Promise = global.Promise; 

var companySchema = new mongoose.Schema ({ 
    name: {type: String, required: true, unique: true}, 
    created: {type: Date, default: Date.now}, 
    active: {type: Boolean, required: true, default: true}, 
    staff: [{ 
     id: { 
      type: mongoose.Schema.Types.ObjectId, 
      ref: "User" 
     }, 
     username: String 
    }], 
    clients: [{ 
     id: { 
      type: mongoose.Schema.Types.ObjectId, 
      ref: "User" 
     }, 
     username: String 
    }] 
}); 

module.exports = mongoose.model("Company", companySchema); 

我在我的路線下面的代碼,但用戶信息沒有被填充到公司對象,什麼是我做錯了?

// EDIT route 
router.get("/:company_id/edit", middleware.checkCompanyOwnership, function(req, res) { 
    Company.findOne({_id: req.params.company_id}).populate({path: 'clients'}).exec(function(err, company) { 
     if (err || !company) { 
      console.log(err); 
      req.flash("error", err.message); 
      res.redirect("/"); 
     } else { 
      console.log("Request to edit company."); 
      //console.log(company); 
      res.render("company/edit", {title: "Edit Company", company: company}); 
     } 
    }); 
}); 

這是,如果我的控制檯日誌公司什麼我得到:

{ _id: 5a070874b4292914444b6e06, 
    name: 'ABC', 
    __v: 1, 
    clients: 
    [ { username: '[email protected]', 
     _id: 5a070206616810129b5c876a } ], 
    staff: [], 
    active: true, 
    created: 2017-11-11T14:25:56.359Z } 

感謝您的幫助。

沙发
0
2

貴公司的模式應該是這樣的

var companySchema = new mongoose.Schema ({ 
    ... 
    staff: [{ type: mongoose.Schema.Types.ObjectId, ref: "User" }], 
    clients: [{ type: mongoose.Schema.Types.ObjectId, ref: "User" }] 
}); 

請參閱該文檔http://mongoosejs.com/docs/populate.html

0
votes
answers
48 views
+10

php7顯示存儲在mongodb中的文件3.4

0

我對php和mongodb很新。我已經在Ubuntu 16.04.3 LTS上安裝了php7.0和mongo 3.4.10。php7顯示存儲在mongodb中的文件3.4

我可以通過輸入蒙戈CLI命令顯示所需的文檔: db.testcollection.find({_id:'superid'}).pretty()

它給了我這樣的結果:

{ "_id" : "superid", "record" : "whatever" }

但我tryig與此PHP腳本顯示從MongoDB的集合文件:

<?php 

    $mongo = new MongoDBDriverManager(); 
    $filter = ['_id' => 'superid']; 
    $options = []; 
    $query = new MongoDBDriverQuery($filter, $options); 
    $rows = $mongo->executeQuery('db.testcollection', $query); 
    foreach ($rows as $document) { 
     print_($document); 
     var_dump($document); 
     echo $document; 
    } 

    echo "The END" 
    ?> 

這隻顯示「結束」。

我很想念我的PHP腳本同樣顯示蒙戈查詢結果爲CLI命令?

沙发
0
0

的問題是: 我創建了使用此命令在蒙戈外殼名爲test的新DATABSE:

use test; 
db.createCollection("testcollection"); 
db.testcollection.insert({ "_id" : "superid", "record" : "whatever"}); 

所以路徑分貝是test.testcollection不db.testcollection。

當我糾正相應的線路是這樣的:

$rows = $mongo->executeQuery('test.testcollection', $query); 

它按預期工作。

我被給出而不需要指定數據庫名稱(即使註銷蒙戈外殼並重新登錄)我正確的結果蒙戈外殼(CLI)混淆。

另一方面,你必須在php中指定dbname.collectionname(有意義):)

0
votes
answers
32 views
+10

MongoDB:我應該一直保持全局會話嗎?

-1

這裏是我的DAO實現的一個片段:MongoDB:我應該一直保持全局會話嗎?

type (
    User struct { 
     Name string `json:"name" bson:"name"` 
     ... 
    } 

    UserDAO struct { 
     *mgo.Database 
    } 
) 

func NewUserDAO() (*UserDAO, error) { 
    session, err := mgo.Dial("mongodb://127.0.0.1:27017/test") 
    if err != nil { 
     return nil, err 
    } 

    return &UserDAO{session.DB("")}, nil 
} 

func (d *UserDAO) Insert(user User) error { 
    return d.C("users").Insert(user) 
} 

func (d *CandleDAO) Find(name string) ([]User, error) { 
    var result []User 
    if err := d.C("users").Find(bson.M{"name": name)}).Sort("time").All(&result); err != nil { 
     return nil, err 
    } 
    return result, nil 
} 

... 

func (d *CandleDAO) Close() { 
    d.Session.Close() 
} 

這裏是我如何調用它:

dao, err := dao.NewUserDAO() 
if err != nil { 
    Log.Error(err.Error()) 
    return 
} 

// close session... is this OK? 
defer dao.Close() 

users, err := dao.Find(&broker.Symbol{"BTC", "USD"}); if err != nil { 
    Log.Error(err.Error()) 
    return 
} 

for i, user := range users { 
    fmt.Printf("%d ==> %v
", i, user) 
} 

上面的代碼工作... ...和我的問題很簡單:我會保持全球mgo.Database實例,或者當我完成時始終關閉會話並在需要時創建新會話是否正確?

+0

相關/可能重複[太多打開文件在mgo去服務器](https://stackoverflow.com/questions/47179890/too-many-open-files-in-mgo-go-server/47180097#47180097 );和[gopkg.in/mgo.v2(Mongo,Go)中的併發]](https://stackoverflow.com/questions/42492020/concurrency-in-gopkg-in-mgo-v2-mongo-go/42495522#42495522) ;和[mgo - 查詢性能似乎一貫很慢(500-650毫秒)](https://stackoverflow.com/questions/40999637/mgo-query-performance-seems-consistently-slow-500-650ms/41000876#41000876)。 – icza

+0

我認爲這可以幫助https://stackoverflow.com/questions/18650890/keeping-open-a-mongodb-database-connection。在我的情況下,我使用go和bigtable,並且保持連接活動(除非/直到服務器崩潰)。 – mayo

+0

非常感謝你,非常感謝:-) – j3d

沙发
0
1

main package docs

新的會話通常是通過調用session.Copy上在撥號時獲得的 初始會話創建。這些新的會話將共享 相同的集羣信息和連接池,並且可能很容易將 交給組織邏輯的其他方法和函數。每創建一個會話都必須在其生命週期結束時調用它的Close方法,因此其資源可能會放回池中或收集起來,取決於具體情況。

含義:在啓動時,你應該Dial並保存會話,併爲每個調用NewUserDAO你應該CloneDial創建初始Session

0
votes
answers
42 views
+10

關係GraphQL

0

第二週,我嘗試鏈接apollo-server-express/MongoDB/Mongoose/GraphQL堆棧中的兩個集合,但我不明白。我發現了一個與REST API相似的課程,我需要的是所謂的關係。我需要這個,但在GraphQL關係GraphQL

watch video

如何車添加到用戶? 我收集的測試服務器,該代碼是在這裏:https://github.com/gHashTag/test-graphql-server 幫助

沙发
0
0

我克隆了你的項目,並實現了一些代碼,這裏我改變了關係的作品。請注意,我只是做了一個基本的代碼,沒有驗證或提前dataloader只是爲了確保非複雜性。希望它可以幫助。

的src/graphql /解析器/轎廂resolvers.js

import Car from '../../models/Car' 
import User from '../../models/User' 

export default { 
    getCar: (_, { _id }) => Car.findById(_id), 
    getCars:() => Car.find({}), 
    getCarsByUser: (user, {}) => Car.find({seller: user._id }), // for relationship 
    createCar: async (_, args) => { 
    // Create new car 
    return await Car.create(args) 
    } 
} 

的src/graphql /分解器/用戶resolvers.js

import User from '../../models/User' 

export default { 
    getUser: (_, { _id }) => User.findById(_id), 
    getUsers:() => User.find({}), 
    getUserByCar: (car, args) => User.findById(car.seller), // for relationship 
    createUser: (_, args) => { 
    return User.create(args) 
    } 
} 

的src/graphql /解析器/index.js

import UserResolvers from './user-resolvers' 
import CarResolvers from './car-resolvers' 

export default { 
    User:{ 
    cars: CarResolvers.getCarsByUser // tricky part to link query relation ship between User and Car 
    }, 
    Car:{ 
    seller: UserResolvers.getUserByCar // tricky part to link query relation ship between User and Car 
    }, 
    Query: { 
    getUser: UserResolvers.getUser, 
    getUsers: UserResolvers.getUsers, 
    getCar: CarResolvers.getCar, 
    getCars: CarResolvers.getCars 
    }, 

    Mutation: { 
    createUser: UserResolvers.createUser, 
    createCar: CarResolvers.createCar, 
    } 
} 

的src/graphql/schema.js

export default` 
    type Status { 
    message: String! 
    } 

    type User { 
    _id: ID! 
    firstName: String 
    lastName: String 
    email: String 
    cars: [Car] 
    } 

    type Car { 
    _id: ID 
    make: String 
    model: String 
    year: String 
    seller: User 
    } 

    type Query { 
    getUser(_id: ID!): User 
    getUsers: [User] 
    getCar(_id: ID!): Car 
    getCars: [Car] 
    } 

    type Mutation { 
    createUser(firstName: String, lastName: String, email: String): User 
    // change from _id to seller, due to base on logic _id conflict with CarId 
    createCar(seller: ID!, make: String, model: String, year: String): Car 
    } 

    schema { 
    query: Query 
    mutation: Mutation 
    } 
` 

的src/middlewares.js

import bodyParser from 'body-parser' 
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express' 
import { makeExecutableSchema } from 'graphql-tools' 

import typeDefs from '../graphql/schema' 
import resolvers from '../graphql/resolvers' 
import constants from './constants' 

export const schema = makeExecutableSchema({ 
    typeDefs, 
    resolvers 
}) 

export default app => { 

    app.use('/graphiql', graphiqlExpress({ 
    endpointURL: constants.GRAPHQL_PATH 
    })) 

    app.use(
    constants.GRAPHQL_PATH, 
    bodyParser.json(), 
    graphqlExpress(req => ({ 
     schema, 
     context: { 
     event: req.event 
     } 
    })) 
) 
} 

enter image description here

enter image description here

enter image description here

enter image description here

+0

非常感謝您,表瞭解一對多通信,但如何使連接多對多? –

板凳
0
0

嘗試做這樣的事情在你的車解析器

export default { 
    getCar: ({ _id: ownId }, { _id }) => 
    Car.findById(ownId || _id); 
// here is the rest of your code 
地板
0
0

您需要在用戶類型添加一個解析器爲cars場。

const resolvers = { 
    Query: { 
    getUsers: ... 
    getCars: ... 
    ... 
    }, 
    Mutation: { 
    ... 
    }, 
    User: { 
    cars: ... 
    } 
} 
0
votes
answers
32 views
+10

(蒙戈)我怎麼能得到與大小

0

沿着在陣列中的有價票券我有一個蒙戈收藏的東西,如以下:(蒙戈)我怎麼能得到與大小

{ 
    "_id" : ObjectId("59e013e83260c739f029ee21"), 
    "createdAt" : ISODate("2017-10-13T01:16:24.653+0000"), 
    "updatedAt" : ISODate("2017-11-11T17:13:52.956+0000"), 
    "age" : NumberInt(34), 
    "attributes" : [ 
     { 
      "year" : "2017", 
      "contest" : [ 
       { 
        "name" : "Category1", 
        "division" : "Department1" 
       }, 
       { 
        "name" : "Category2", 
        "division" : "Department1" 
       } 
      ] 
     }, 
     { 
      "year" : "2016", 
      "contest" : [ 
       { 
        "name" : "Category2", 
        "division" : "Department1" 
       } 
      ] 
     }, 
     { 
      "year" : "2015", 
      "contest" : [ 
       { 
        "name" : "Category1", 
        "division" : "Department1" 
       } 
      ] 
     } 
    ], 
    "name" : { 
     "id" : NumberInt(9850214), 
     "first" : "john", 
     "last" : "afham" 
    } 
} 

現在我怎麼能拿誰擁有的文件數量競賽名稱爲組別超過一次或2次以上......等等

我試圖用規模和$ GT,但不能形成正確的結果

+0

粘貼集合中的示例數據。這個數據看起來不對 – Astro

+0

看起來像上面的數據是不正確的 – Sam

+0

@astro我已經更新json數據,這是100%喜歡從集合中提取 –

沙发
0
2

假設一個contest絕不會含有相同的name(例如「組別」)值超過一次,這裏是你可以做什麼。

沒有任何unwind S的將導致特別改進的性能上大集或數據集與您attributes陣列條目的負荷。

db.collection.aggregate({ 
    $project: { 
     "numberOfOccurrences": { 
      $size: { // count the number of matching contest elements 
       $filter: { // get rid of all contest entries that do not contain at least one entry with name "Category1" 
        input: "$attributes", 
        cond: { $in: [ "Category1", "$$this.contest.name" ] } 
       } 
      } 
     } 
    } 
}, { 
    $match: { // filter the number of documents 
     "numberOfOccurrences": { 
      $gt: 1 // put your desired min. number of matching contest entries here 
     } 
    } 
}, { 
    $count: "numberOfDocuments" // count the number of matching documents 
}) 
+0

這裏使用了數組點運算(this.contest.name)! –

板凳
0
0

試試這個關於大小。

db.foo.aggregate([ 
    // Start with breaking down attributes: 
    {$unwind: "$attributes"} 

    // Next, extract only name = Category1 from the contest array. This will yield     
    // an array of 0 or 1 because I am assuming that contest names WITHIN 
    // the contest array are unique. If found and we get an array of 1, turn that     
    // into a single doc instead of an array of a single doc by taking arrayElemAt 0.     
    // Otherwise, "x" is not set into the doc AT ALL. All other vars in the doc 
    // will go away after $project; if you want to keep them, change this to 
    // $addFields: 
    ,{$project: {x: {$arrayElemAt: [ {$filter: { 
      input: "$attributes.contest", 
      as: "z", 
      cond: {$eq: [ "$$z.name", "Category1" ]} 
       }}, 0 ]} 
    }} 

    // We split up attributes before, creating multiple docs with the same _id. We     
    // must now "recombine" these _id (OP said he wants # of docs with name). 
    // We now have to capture all the single "x" that we created above; docs without     
    // Category1 will have NO "x" and we don't want to include them in the count.      
    // Also, we KNOW that name can only be Category 1 but division could vary, so      
    // let's capture that in the $push in case we might want it: 
    ,{$group: {_id: "$_id", x: {$push: "$x.division"}}} 

    // One more pass to compute length of array: 
    ,{$addFields: {len: {$size: "$x"}} } 

    // And lastly, the filter for one time or two times or n times: 
    ,{$match: {len: {$gt: 2} }} 

    ]); 
地板
0
0

首先,我們需要通過屬性和競賽字段來平整文檔。然後由文件初始_id和比賽名稱統計不同的比賽。最後,我們過濾結果。

db.person.aggregate([ 
    { $unwind: "$attributes" }, 
    { $unwind: "$attributes.contest" }, 

    {$group: { 
       _id: {initial_id: "$_id", contest: "$attributes.contest.name"}, 
       count: {$sum: 1} 
      } 
    }, 
    {$match: {$and: [{"_id.contest": "Category1"}, {"count": {$gt: 1}}]}}]); 
+0

Double $ unwind在更大的陣列情況下可能是致命的。 drickless發佈了上面的$ unwind-free示例。 –

+0

@ BuzzMoschetti也許它可以,drickless已經對數據做了一些假設,而我沒有。無論如何,這是很好的選擇可供選擇。 –

0
votes
answers
60 views
+10

MongoDB的Pymongo創建嵌套對象

2

索引我有像這樣的對象:MongoDB的Pymongo創建嵌套對象

{ 
    "field1": "somestring", 
    "field2": { 
     "nestedfield1": "somestring", 
     "nestedfield2": "somestring" 
    } 
} 

我可以像這樣db.collection.createIndex('field1')創建FIELD1指數如預期它會奏效。但是如果我想在兩個嵌套字段上都有一個索引呢?

我必須做db.collection.createIndex('field2.nestedfield1')來創建那個索引還是會db.collection.createIndex('field2')自動創建那個?

我將在我的查詢中使用'field2.nestedfield1'進行搜索,並希望得到一個索引。

謝謝

沙发
0
1

你不能一次索引嵌套字段,你必須分別索引每個項目。

要在嵌套字段上創建索引,只需給出其完整字段路徑即可。分離器,

db.collection.createIndex('field2.nestedfield1') 
+0

謝謝!回答它 –

0
votes
answers
75 views
+10

Mongodb多租戶設計時間序列數據

0

我正在開發時間序列數據的IOT應用程序。該應用程序將作爲多租戶的SaaS提供。 我決定去fir mongodb作爲我的數據庫。多租戶時間序列數據的設計應該是什麼?Mongodb多租戶設計時間序列數據

我應該爲每個客戶端的不同文檔或每個客戶端的不同數據庫?因爲我讀過每個客戶端的不同集合在MongoDb中被認爲是糟糕的設計。

沙发
0
0

對於多租戶,考慮爲每個租戶單獨的數據庫。這增加了租戶數據的隱私性。

0
votes
answers
27 views
+10

無法連接即時通訊使用MongoDB的V 3.4,並嘗試啓動服務器,以蒙戈服務器

0

enter image description here但它說無法連接即時通訊使用MongoDB的V 3.4,並嘗試啓動服務器,以蒙戈服務器

C:Usersgokul ram>mongo 
MongoDB shell version v3.4.10 
connecting to: mongodb://127.0.0.1:27017 
2017-11-18T09:25:27.061+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017 after 5000ms milliseconds, giving up. 
2017-11-18T09:25:27.062+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed : 
[email protected]/mongo/shell/mongo.js:237:13 
@(connect):1:6 
exception: connect failed 

我也試圖與--dbpath命令,但它在等待了很長一段時間的連接,仍然沒有連接

C:Program FilesMongoDBServer3.4in>mongod --dbpath "C:/data/db" 
2017-11-18T09:36:03.368+0530 I CONTROL [initandlisten] MongoDB starting :  pid=4660 port=27017 dbpath=C:/data/db 64-bit host=GOK_RAM 
2017-11-18T09:36:03.370+0530 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2 
2017-11-18T09:36:03.370+0530 I CONTROL [initandlisten] db version v3.4.10 
2017-11-18T09:36:03.371+0530 I CONTROL [initandlisten] git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9 
2017-11-18T09:36:03.371+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips 22 Sep 2016 
2017-11-18T09:36:03.371+0530 I CONTROL [initandlisten] allocator: tcmalloc 
2017-11-18T09:36:03.371+0530 I CONTROL [initandlisten] modules: none 
2017-11-18T09:36:03.371+0530 I CONTROL [initandlisten] build environment: 
2017-11-18T09:36:03.371+0530 I CONTROL [initandlisten]  distmod: 2008plus-ssl 
2017-11-18T09:36:03.371+0530 I CONTROL [initandlisten]  distarch: x86_64 
2017-11-18T09:36:03.372+0530 I CONTROL [initandlisten]  target_arch: x86_64 
2017-11-18T09:36:03.372+0530 I CONTROL [initandlisten] options: { storage: { dbPath: "C:/data/db" } } 
2017-11-18T09:36:03.375+0530 I -  [initandlisten] Detected data files in C:/data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'. 
2017-11-18T09:36:03.376+0530 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1509M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0), 
2017-11-18T09:36:04.096+0530 I CONTROL [initandlisten] 
2017-11-18T09:36:04.097+0530 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 
2017-11-18T09:36:04.097+0530 I CONTROL [initandlisten] **   Read and write access to data and configuration is unrestricted. 
2017-11-18T09:36:04.098+0530 I CONTROL [initandlisten] 
2017-11-18T09:36:04.098+0530 I CONTROL [initandlisten] Hotfix KB2731284 or later update is not installed, will zero-out data files. 
2017-11-18T09:36:04.098+0530 I CONTROL [initandlisten] 
2017-11-18T09:36:05.880+0530 I FTDC  [initandlisten] Initializing full-time diagnostic data capture with directory 'C:/data/db/diagnostic.data' 
2017-11-18T09:36:05.882+0530 I NETWORK [thread1] waiting for connections on port 27017 

這是與mongo db版本或我的配置問題?任何面臨同樣的問題,請幫助我!在此先感謝

沙发
0
0

首先 我們需要與--dbpath命令

下一頁開放單獨的命令窗口中啓動蒙戈服務器, 套裝路徑到mongo bin並使用mongo.exe命令

然後您可以開始訪問mongo服務器。

板凳
0
0

首先:導航到C:Program FilesMongoDBServer3.4in和運行mongod.exe這將啓動服務器。

第二:在一個新的CMD typein 蒙戈 這可能工作

+0

第一步了連接失敗 C: Program Files文件 MongoDB的服務器 3.4 BIN> mongo.exe MongoDB的外殼版本v3.4.10 連接到:MongoDB的://127.0.0.1:27017 2017年-11-18T10:24:44.712 + 0530 W NETWORK [thread1]在5000毫秒毫秒後無法連接到127.0.0.1:27017,放棄。 2017-11-18T10:24:44.712 + 0530 E QUERY [thread1]錯誤:無法連接到服務器127.0.0.1:27017,連接嘗試失敗: [email protected]/mongo/shell/mongo.js:237: 13 @(連接):1:6 異常:連接失敗 –

+0

查看路徑是否正確手動查看文件夾結構 – Vignesh

+0

可以給我一個你的cmd的屏幕截圖,錯誤 – Vignesh

地板
0
0

您首先需要開始使用「mongod.exe」命令,並設置「數據 DB」蒙戈服務器DBPATH其中數據將被存儲。確保在運行命令之前創建文件夾。 將C: Program Files MongoDB Server 3.4 bin 添加到您的環境變量'PATH'將是有益的。 要運行服務器類型在命令提示符以下命令: 的mongod --dbpath = C:數據分貝 服務器應在端口與默認設置運行27017

要連接到服務器,打開另一個命令提示符並執行'mongo.exe'命令。這應該工作。 其他你可以嘗試指定端口號「蒙戈--port 27017」

+0

我也這麼做過。但仍面臨同樣的問題。任何其他的選擇? –

+0

你能添加「mongod.exe」命令的截圖嗎? 您也可以嘗試將mongod安裝爲Windows服務,這將要求您創建mongod.conf文件並安裝 –

0
votes
answers
83 views
+10

使用Robo 3T連接到遠程MongoDB

1

我試圖在Mac下使用Robomongo(或Robo 3T)來控制遠程Ubuntu & Nginx服務器中的我的mongodb。使用Robo 3T連接到遠程MongoDB

通常情況下,我需要在終端上使用ssh xxx.xx.xx.xx,並使用用戶名和密碼連接到服務器。在/etc/nginx/sites-enabled/myweb.io,有listen 443 ssl

在Robo 3T中,我試圖建立與Use SSH tunnel的連接。我嘗試了端口號44380。但它給了我一個錯誤:Error: Resource temporarily unavailable. Error when starting up SSH session: -13. (Error #35)

有誰知道如何解決這個問題?

enter image description here

+0

嘗試連接而不SSH隧道和SSH在端口22上運行(如果你沒有改變它,但你應該改變它)。 – Shubhamoy

+0

如果我沒有SSH隧道連接,我應該使用哪種方式? – SoftTimur

+0

只需取消SSH隧道並嘗試連接。 – Shubhamoy

沙发
0
1

正確的設置是

SSH

1)下,檢查User SSH tunnel,使用端口22

2)和下Connection,寫127.0.0.1:27017

0
votes
answers
43 views
+10

更新整個子元素的NodeJS

1

考慮下面的文件,我想更新與_id數據集的整場:123,更新整個子元素的NodeJS

"data": { 
      "_id": "1234546", 
      "dataset": [ 
       { 
        "_id": "123", 
        "el2": "asd", 
        "el3": "sd", 
        "el4": "gfdd", 
        "el5": "asdfa", 
       }, 
       { 
        "_id": "787", 
        "el2": "asd", 
        "el3": "sd", 
        "el4": "gfdd", 
        "el5": "asdfa", 
       }, 
       { 
        "_id": "898", 
        "el2": "asd", 
        "el3": "sd", 
        "el4": "gfdd", 
        "el5": "asdfa", 
       }, 
       { 
        "_id": "564", 
        "el2": "asd", 
        "el3": "sd", 
        "el4": "gfdd", 
        "el5": "asdfa", 
       }, 
      ] 
     } 

我想更新的所有領域數組元素通過使用_id字段。

我使用

getDB.collection ('data').findOneAndUpdate(
    { _id: new ObjectId(data.userId), 
     "dataset._id":new ObjectId(data.dataset), 
    }, 
    { $set: { "userAddress.$":newdataset } }, 
    {returnOriginal:false}}); 

請提出了一些很好的選擇進行更新。

在此先感謝.. :)

沙发
0
1

如果你想只更新數據庫服務器上的文檔,而無需讀取它,你可以使用更新,而不是findOneAndUpdate。

這裏有一種方法來做到這一點。

collection('data').update({ 
     _id:<_id>, 
     "dataset._id":<dataset._id> 
    },{ 
     $set:{ 
     "dataset.$.el2":<el2>, 
     "dataset.$.el3":<el3>, 
     "dataset.$.el4":<el4>, 
     "dataset.$.el5":<el5> 
     } 
    }) 
+0

謝謝!!!法魯克 –

+0

歡迎您:) –