質問編集履歴

4

変更

2019/07/30 12:00

投稿

aiai8976
aiai8976

スコア112

test CHANGED
File without changes
test CHANGED
@@ -14,11 +14,49 @@
14
14
 
15
15
  ```
16
16
 
17
+ $ sudo node webServer.js
18
+
19
+ Server running at http://localhost:80/
20
+
21
+ /
22
+
23
+ /js/three.js-master/build/three.min.js
24
+
25
+ /js/OrbitControls.js
26
+
27
+ /get_value
28
+
29
+ レスポンス
30
+
31
+ []
32
+
33
+ _http_outgoing.js:595
34
+
35
+ throw new ERR_INVALID_ARG_TYPE('first argument',
36
+
37
+ ^
38
+
39
+
40
+
41
+ TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string or Buffer. Received type object
42
+
17
- console.log("はいった!!!!!");
43
+ at write_ (_http_outgoing.js:595:11)
44
+
45
+ at ServerResponse.write (_http_outgoing.js:567:10)
46
+
47
+ at Object.getValue (/home/hasegawa/デスクトップ/akiyama/Node.js/webServer.js:104:17)
48
+
49
+ at Server.<anonymous> (/home/hasegawa/デスクトップ/akiyama/Node.js/webServer.js:128:29)
50
+
51
+ at Server.emit (events.js:198:13)
52
+
53
+ at parserOnIncoming (_http_server.js:677:12)
54
+
55
+ at HTTPParser.parserOnHeadersComplete (_http_common.js:109:17)
18
56
 
19
57
  ```
20
58
 
21
- これがうまく表示されずに次のログである「レスポンス」が表示されてしまいます。
59
+ 「connected successfully」がうまく表示されずに次のログである「レスポンス」が表示されてしまいます。
22
60
 
23
61
 
24
62
 

3

変更

2019/07/30 12:00

投稿

aiai8976
aiai8976

スコア112

test CHANGED
File without changes
test CHANGED
@@ -322,6 +322,6 @@
322
322
 
323
323
  ### 補足情報(FW/ツールのバージョンなど)
324
324
 
325
-
325
+ mongo:4.0.10
326
326
 
327
327
  OS:Ubuntu

2

変更

2019/07/30 11:05

投稿

aiai8976
aiai8976

スコア112

test CHANGED
File without changes
test CHANGED
@@ -136,9 +136,11 @@
136
136
 
137
137
  // 接続文字列
138
138
 
139
- const url = 'mongodb://127.0.0.1:27017/study';
139
+ const url = 'mongodb://localhost:27017';
140
+
140
-
141
+ const dbName='study';
142
+
141
-
143
+ const assert=require('assert')
142
144
 
143
145
  var result=new Array();
144
146
 
@@ -146,33 +148,63 @@
146
148
 
147
149
  // MongoDB へ 接続
148
150
 
149
- MongoClient.connect(url, (error, db) => {
151
+ MongoClient.connect(url, function(err, client){
150
-
152
+
151
- var collection;
153
+ assert.equal(null,err);
152
-
154
+
153
- console.log("はいった!!!!!");
155
+ console.log("Connected successfully to server");
156
+
157
+
158
+
154
-
159
+ const db=client.db(dbName);
160
+
161
+
162
+
155
-
163
+ findDocuments(db,function() {
164
+
165
+ client.close();
166
+
167
+ });
168
+
169
+
170
+
171
+ // コレクション中で条件に合致するドキュメントを取得
172
+
173
+ // collection.find({price: {$lt: 2000}}).toArray((error, documents)=>{
174
+
175
+ // for (var document of documents) {
176
+
177
+ // console.log(document.name);
178
+
179
+ // }
180
+
181
+ // });
182
+
183
+ db.close();
184
+
185
+ });
186
+
187
+
188
+
189
+ const findDocuments=function(db,callback) {
156
190
 
157
191
 
158
192
 
159
193
  // コレクションの取得
160
194
 
161
- collection = db.collection("user");
195
+ const collection = db.collection("user");
162
196
 
163
197
 
164
198
 
165
199
  // コレクションに含まれるドキュメントをすべて取得
166
200
 
167
- collection.find().toArray((error, documents) => {
201
+ collection.find({}).toArray(function(err, documents) {
202
+
168
-
203
+ assert.equal(err,null)
169
-
170
204
 
171
205
  for (var document of documents) {
172
206
 
173
- console.log(document.dist);
174
-
175
- console.log(document.rot);
207
+ console.log("Found the following records")
176
208
 
177
209
  result=push(document.dist);
178
210
 
@@ -180,38 +212,24 @@
180
212
 
181
213
  }
182
214
 
215
+ callback(documents);
216
+
183
217
  });
184
218
 
185
-
219
+ }
186
-
220
+
221
+
222
+
187
- // クショ中で条件に合致するドキュメントを取得
223
+ // HTTPスポスヘッダを出力する
188
-
224
+
189
- // collection.find({price: {$lt: 2000}}).toArray((error, documents)=>{
225
+ res.writeHead(200, {
190
-
226
+
191
- // for (var document of documents) {
227
+ 'content-Type': 'text/html'
192
-
193
- // console.log(document.name);
194
-
195
- // }
196
-
197
- // });
198
-
199
- db.close();
200
228
 
201
229
  });
202
230
 
203
231
 
204
232
 
205
- // HTTPレスポンスヘッダを出力する
206
-
207
- res.writeHead(200, {
208
-
209
- 'content-Type': 'text/html'
210
-
211
- });
212
-
213
-
214
-
215
233
  console.log("レスポンス");
216
234
 
217
235
  console.log(result);
@@ -254,8 +272,6 @@
254
272
 
255
273
  Response["getThree"]();
256
274
 
257
- console.log("OK")
258
-
259
275
  return;
260
276
 
261
277
  } else if (uri === "/js/OrbitControls.js") {
@@ -282,7 +298,7 @@
282
298
 
283
299
  // 指定されたポート(8080)でコネクションの受け入れを開始する
284
300
 
285
- server.listen(80)
301
+ server.listen(80);
286
302
 
287
303
  console.log('Server running at http://localhost:80/');
288
304
 
@@ -290,6 +306,8 @@
290
306
 
291
307
 
292
308
 
309
+
310
+
293
311
  ```
294
312
 
295
313
 

1

誤字

2019/07/30 11:02

投稿

aiai8976
aiai8976

スコア112

test CHANGED
File without changes
test CHANGED
@@ -28,7 +28,7 @@
28
28
 
29
29
  ### 該当のソースコード
30
30
 
31
-
31
+  
32
32
 
33
33
  ```ここに言語名を入力
34
34