@Vũ Mình tìm ra rồi à aggregate trong mongoose
Phạm Minh Kha
@Kha Pham
Best posts made by Kha Pham
-
RE: Hỏi về cách custom field trong mongoose?
-
RE: Video không thể load ở local Nodejs?
Mình đã tìm được nguyện nhân rồi. Do file mp4 của mình mã hóa ở h256 nên chrome không thể đọc được và chỉ chạy trên internet explorer.
-
RE: Lỗi mongoDB khi đưa lên server?
được rồi. chạy thêm dòng
db.adminCommand({setFeatureCompatibilityVersion: "3.6"})
trên server là chạy bình thường
-
RE: Cách update tối ưu nhất trong mongoDB
@Vụ-Chu ko mình update toàn dùng _id. Dùng id để xác định document rồi mới update
-
RE: Share code web clone mp3.zing.vn phiên bản single page viết bằng Nodejs + React
@Anh-Thi bạn tự học mà xây dựng được thế này là quá giỏi rồi
-
RE: Failed to serialize user into session login google nodejs
@Minh-Sang xem log newuser thế nào
-
Hỏi cách limit document trả về trong hàm $lookup hoặc $graphLookup mongodb?
Mình đang truy suất 1 bảng comment trong đó có comment_cha sẽ được lòng các comment_con vào thông qua _id nhưng mình không biết cách limit số lượng con. Mong mấy bạn giúp hoặc gốp ý cách nào tối ưu hơn.
exports.loadComments = function (req, res) { var slug = req.query.slug; if(!slug) return res.json({error: "Không lấy được slug bài viết"}); var trang = req.query.page ? req.query.page : 1; var limit = config.limit; var skip = (trang - 1) * limit; var tempArray = []; commentsModel.aggregate([ {$project: {_id: 1, user_ObjectId: 1, comment_ObjectId: 1, commentContent: 1, commentModify: 1, post_slug: 1, point: {$subtract: ['$commentUpVote','$commentDownVote']}}}, {$match : { post_slug : slug, comment_ObjectId: null } }, {$sort : { point : -1, commentModify: -1 } }, { $lookup: { from: "users", localField: "user_ObjectId", foreignField: "_id", as: "user" } }, { $graphLookup: { //Chổ này là nó truy xuất lòng nhau mà không biết phải thêm chữ gì vô cho nó limit lại đã thử thêm $limit nhưng lỗi from: "comments", startWith: "$_id", connectFromField: "_id", connectToField: "comment_ObjectId", as: "Comments_child" } }, { $skip: skip }, { $limit: 2 } ], function (err, result) { if (err) { console.log(err); res.json({'error': 'Không kết nối được máy chủ! F5 thử lại'}) } else { var data = ({page: parseInt(trang) + 1, comments: result}) return res.json(data); } }).allowDiskUse(true); }
//dữ liệu trã về { "page": 2, "comments": [ { "_id": "5b24bc26e281911588e79b9a", "comment_ObjectId": null, "commentContent": "9", "post_slug": "0Pxzb9f", "user_ObjectId": "5b1f417ba5290e11d4c39f1f", "commentModify": "2018-06-16T07:28:38.442Z", "t": null, "point": 0, "user": [ { "_id": "5b1f417ba5290e11d4c39f1f", "quyen_hang": 3, "ten_dang_nhap": "1633029573462982", "mat_khau": "$2b$10$i5KY9I.C.mES4vtoRXri2exzKoy97L6jsop7LKm02ktRK/QyKVzRi", "email": "[email protected]", "anh_dai_dien": "images/avatar/1633029573462982.jpg", "ten": "Kha Pham", "mang_xa_hoi": { "facebook": [ { "id": "1633029573462982" } ] }, "__v": 0 } ], "Comments_child": [ // có cách nào để limit cái này theo ý mình không { "_id": "5b24bc1de281911588e79b94", "commentUpVote": 0, "commentDownVote": 0, "comment_ObjectId": "5b24bc26e281911588e79b9a", "commentContent": "3", "commentStatus": 1, "commentImage": { "type": null, "url": null, "video": null }, "post_slug": "0Pxzb9f", "user_ObjectId": "5b1f417ba5290e11d4c39f1f", "commentCreate": "2018-06-16T07:28:29.531Z", "commentModify": "2018-06-16T07:28:29.531Z", "__v": 0 }, { "_id": "5b24bc1ce281911588e79b93", "commentUpVote": 0, "commentDownVote": 0, "comment_ObjectId": "5b24bc26e281911588e79b9a", "commentContent": "2", "commentStatus": 1, "commentImage": { "type": null, "url": null, "video": null }, "post_slug": "0Pxzb9f", "user_ObjectId": "5b1f417ba5290e11d4c39f1f", "commentCreate": "2018-06-16T07:28:28.447Z", "commentModify": "2018-06-16T07:28:28.447Z", "__v": 0 }, { "_id": "5b24bc1be281911588e79b92", "commentUpVote": 0, "commentDownVote": 0, "comment_ObjectId": "5b24bc26e281911588e79b9a", "commentContent": "1", "commentStatus": 1, "commentImage": { "type": null, "url": null, "video": null }, "post_slug": "0Pxzb9f", "user_ObjectId": "5b1f417ba5290e11d4c39f1f", "commentCreate": "2018-06-16T07:28:27.461Z", "commentModify": "2018-06-16T07:28:27.461Z", "__v": 0 } ] }, { "_id": "5b24bc25e281911588e79b99", "comment_ObjectId": null, "commentContent": "8", "post_slug": "0Pxzb9f", "user_ObjectId": "5b1f417ba5290e11d4c39f1f", "commentModify": "2018-06-16T07:28:37.442Z", "t": null, "point": 0, "user": [ { "_id": "5b1f417ba5290e11d4c39f1f", "quyen_hang": 3, "ten_dang_nhap": "1633029573462982", "mat_khau": "$2b$10$i5KY9I.C.mES4vtoRXri2exzKoy97L6jsop7LKm02ktRK/QyKVzRi", "email": "[email protected]", "anh_dai_dien": "images/avatar/1633029573462982.jpg", "ten": "Kha Pham", "mang_xa_hoi": { "facebook": [ { "id": "1633029573462982" } ] }, "__v": 0 } ], "Comments_child": [] } ] }
graphLookup document
https://docs.mongodb.com/manual/reference/operator/aggregation/graphLookup/index.html#examples -
RE: Hỏi về cách chuyển ascii, html code thành text từ response json
@Vũ Big thank. đã làm được khi cài https://github.com/wrakky/react-html-parser thêm vào
-
RE: Id facebook
Bạn cần phải xác thực ứng dụng, rồi quay clip cách hoạt động của những gì bạn lấy nữa
Latest posts made by Kha Pham
-
RE: Share code web clone mp3.zing.vn phiên bản single page viết bằng Nodejs + React
@Anh-Thi phần karaoke xử lý sao vậy bác
-
Hỏi về webpack-dev-server và sessionID của nodejs?
- Tình hình là chạy chế độ webpack-dev-server: mình xây dựng web client reactjs chạy ở port 4000 còn server nodejs chạy port 8080 ở client thì mình gọi api đến server mỗi lần gọi server tạo 1 SessionID khác nhau nên kiểm tra đăng nhập bằng session không được.
- Còn trường hợp chạy chế độ webpack ra file bundle.js rồi thì server chạy bình thường.
Mỗi lần gửi request là 1 sessionid khác nhau.
chay port 4000
Khi xuất file và chạy bằng nodejs
-
RE: Moi nguoi cho em hoi ve mongoose vs nodejs a
@CodeConCat thấy là không muốn đọc rồi haha
-
RE: Cần giúp đỡ về react router?
Mình tìm được bài viết rồi. Do server và client của mình chạy khác port nên dùng HashRouter để tránh gửi request lên server khi deloy thì chuyển về như củ là được.
-
Cần giúp đỡ về react router?
mình muốn bỏ /#/ ra khỏi url mà không biết cách nào. khi không sử dụng HashRouter mà dùng Router thì nó bị lỗi không get được url
import { BrowserRouter as Router, Route, Link, withRouter, HashRouter } from "react-router-dom"; ReactDOM.render( <Provider store={store} > <HashRouter> <div> <Nav /> <Route exact path="/" component={HomePage} /> <Route path="/v/:slug" component={ViewPage} /> <Route path="/login" component={LoginPage} /> <Route path="/new" component={HomePage} /> <Route path="/fetch9Gag" component={fetch9Gag} /> <Route path="/fetchHaiVN" component={fetchHaiVN} /> <Route path="/fetchXemVN" component={fetchXemVN} /> <Route path="/profile" component={ProfilePage} /> <Route path="/c/:slug" component={HomePage} /> </div> </HashRouter> </Provider> , document.getElementById('root') );
-
RE: Hỏi về change IP với nodejs
@Thành187 bạn dùng axios + proxy
Thường thì dùng 1 proxy đến khi nó block rồi chuyển sang 1 proxy khác.
Proxy có thể tìm trên google với cú pháp free proxy -
RE: Đa ngôn ngữ trong API sử dụng nodejs
Theo mình nghĩ thì là lưu ở session rồi check ở session ngôn ngữ gì thì làm.
-
RE: Lỗi mongoDB khi đưa lên server?
được rồi. chạy thêm dòng
db.adminCommand({setFeatureCompatibilityVersion: "3.6"})
trên server là chạy bình thường