2015-02-07 42 views
1

我有這樣一個模式:我想顯示特定日期的attendnce MongoDB中

   var UserSchema = new Schema({ 
      name: String, 
       username: { type: String, required: true, index: { unique: true }}, 
      password: { type: String, required: true, select: false }, 
      attendence: [{ 
        month :{type:String}, 
        year :{type:String}, 
        day  :{ type:String}, 
        attended:{type: Boolean} 

      }]   
     }); 

我想說明的出席即此考勤每個日期(按月+一年+天相結合)針對角度js表中的每個用戶名與節點jj和mongodb。在moongose。

+0

而你在哪裏停留在所有這些任務?你不知道如何查詢mongo嗎?或者你有麻煩顯示結果的角度?你試過什麼了? – joao 2015-02-07 10:54:55

+0

順便說一句,Mongo具有[日期類型](http://docs.mongodb.org/manual/reference/bson-types/),因此您不必像那樣存儲它。 – laggingreflex 2015-02-07 11:21:42

+0

與日期類型它也顯示時間。我不想要時間becauz造成歧義。我想存儲每個用戶的特定日期的單個記錄 – 2015-02-09 06:08:42

回答

0

希望這個代碼將有助於ü..

這是客戶端的角度js代碼到userdetaile使用日期和時間插入數據庫。

<form method="post" name="ravi" action="/"> 
    username: <input type="text" placeholder="username" name="user" required><br/> 
    date :<input type="number" placeholder="year" name="year" min="2015" max="2017" required> 
     <input type="number" placeholder="month" name="month" min="1" max="12" required> 
     <input type="number" placeholder="day" name="day" min="1" max="31" required><br/> 
    Time: <input type="number" placeholder="HH" name="hour" min="0" max="23" required> 
     <input type="number" placeholder="MM" name="minutes" min="0" max="59" required><br/> 
      <input type="submit" > 
    </form> 

這是服務器端使用日期和時間,在數據庫中插入userdetaile ..

MongoClient.connect("mongodb://localhost:27017/bhawna", function(err, db) { 
    if(err) { return console.dir(err); } 
    var collection2 = db.collection('sadulehistory'); 


    var searchitem = (req.body.user).toUpperCase(); 
    console.log(searchitem); 
    //var searchitem1 =(req.params.aa) 
    //console.log(JSON.stringify(req.body.search)); 
    var yr = req.body.year; 
    var moy = req.body.month; 
    var dom = req.body.day; 
    var hr = req.body.hour; 
    var mnt = req.body.minutes; 


    collection2.insert({ 
     'searchitem': searchitem, 
     'Scheduledtime': (new Date(yr, (moy - 1), dom, hr, mnt)).toLocaleString(), 
     'CurrentTime': (new Date()).toLocaleString() 
    }, function(err, result) {}); 

    res.setHeader("Access-Control-Allow-Origin", "http://localhost:3000/") 
    res.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS"); 
    res.setHeader("Access-Control-Allow-Headers", "Content-Type"); 
    res.redirect('back'); 
}); 
+0

---------------------------------- 名稱出席20-10-2015 ------------------------------------ Akash true Nitin False ----------------------------------我希望像這樣在這個特定日期其結果顯示...我想在表 – 2015-02-17 06:12:47

+0

中顯示它,請解釋你想要顯示文件的格式 – 2015-02-17 09:27:36

+0

我做了一個下拉頁面,我們選擇日期,月份和年份,並進入網址如http:// localhost:8080/users/showA ttendence/6/1/2015其中6日期,1個月和2015年,然後在下一頁上,我想顯示一個表格,其中包含名稱和其他顯示日期在這個網址 – 2015-02-17 09:40:14

0

你好bhawna這個代碼必須幫助你... 考勤客戶端爲用戶考勤碼..index.html

<html> 
    <head> 
    <title>Attendence</title> 
    <script src="angular.min.js"></script> 
    </head> 
    <body bgcolor="gray"> 

    <a href="Shistory.html">Attendence Listing</a> 
    <div id="container" > 
     <h1 align="center"> Attendence </h1> 
<div align="center"> 
<form method="post" name="ravi" action="/"> 
<input type="text" placeholder="Name" name="Item" required><br/> 
date :<input type="number" placeholder="year" name="year" min="2015" max="2017" required> 
    <input type="number" placeholder="month" name="month" min="1" max="12" required> 
    <input type="number" placeholder="day" name="day" min="1" max="31" required><br/> 
attended:<select name="attended"> 
    <option value="Present">Present</option> 
    <option value="Absent">Absent</option> 
    </select> 
<br/> 
     <input type="submit" value="Insert attendence" > 
</form> 
</div> 

    </div> 
    </body> 
</html> 

以及使用日期代碼搜索用戶的代碼.. Shistor y.html

<html> 
    <head> 
    <title>Attendence</title> 
    <script src="angular.min.js"></script> 
    </head> 
    <body bgcolor="gray"> 
    <a href="index.html">Attendence</a> 
    <div id="container" > 
<div align="center"> 
<h1 align="center"> Attendence Listing </h1> 
<form method="post" name="ravi1" action="/a"> 
date :<input type="number" placeholder="year" ng-model="year" name="year" min="2015" max="2017" required> 
    <input type="number" placeholder="month" ng-model="month" name="month" min="1" max="12" required> 
    <input type="number" placeholder="day" ng-model="day" name="day" min="1" max="31" required><br/> 
    <input type="submit" value="attendence"> 
</form> 
</div> 


    </div> 
    </body> 
</html> 

和你的服務器端代碼.. server.js

var MongoClient = require('mongodb').MongoClient; 
var connect = require('connect'), 
bodyParser = require('body-parser') 
var ObjectId=require('mongodb').ObjectID; 
var  BSON = require('mongodb').pure().BSON, 
    express = require("express"), 
    app = express(); 
app.use(bodyParser.json()); 
app.use(bodyParser.urlencoded({ 
    extended: true 
})); 


     // app.use(express.bodyParser()); 
     app.use(express.static(__dirname + '/angular')); 
    // index.html and Sdistory.html in public folder 
     app.use(express.static(__dirname + '/public')); 
      app.get("/",function(req,res){ 
       res.sendFile(__dirname+'/index.html'); 
      }); 


     MongoClient.connect("mongodb://localhost:27017/bhawna", function(err, db) { 
      if(err) { return console.dir(err); } 
      var collection2 = db.collection('users'); 
     app.post('/a',function(req,res){ 
     //console.log("hello"); 

     var qqw=req.body.year; 
     var qqw2=req.body.month; 
     var qqw3=req.body.day; 
        collection2.find({'Scheduledtime':(new Date(qqw, (qqw2-1), qqw3)).toLocaleString()}).toArray(function(err,resu) 
     { 
      res.end(JSON.stringify(resu)); 
     console.log(resu); 
             } 
     ); 
     }); 
     app.post('/',function(req,res){ 

     var searchitem =(req.body.Item).toUpperCase(); 

       var yr=req.body.year; 
       var moy=req.body.month; 
       var dom=req.body.day; 
       var attended=req.body.attended; 

     collection2.insert({'userd':searchitem,'Scheduledtime':(new Date(yr, (moy-1), dom)).toLocaleString(),'Attended':attended},function(err,result){}); 

     res.setHeader("Access-Control-Allow-Origin","http://localhost:8080/") 
       re 

s.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS"); 
      res.setHeader("Access-Control-Allow-Headers", "Content-Type"); 
    res.redirect('back'); 



     }); 
    }); 
    app.listen(8080,function(){ 
     console.log("It's Started on PORT 8080"); 
    }); 
+0

我大部分我也做了....我拿着attendence ie app.post('/',函數(需要,水庫)的一部分,我需要獲取記錄的表格形式 – 2015-02-18 06:05:49

+0

然後你需要angularjs這個.. – 2015-02-18 06:11:09

+0

是在前面 - 結束我用angularjs來顯示錶 – 2015-02-18 06:21:23

相關問題