从Mongoose获取在模式中设置为唯一的字段

时间:2015-12-04 21:49:48

标签: node.js mongodb mongoose schema unique

我希望检查schema中的哪些字段设置为unique,类似于通过indexes获取schema的{​​{1}}。可以在MyCollection.collection.getIndexes()对象的某处找到此信息吗?

1 个答案:

答案 0 :(得分:2)

试试这个:

static void MovePlayer(int playerNo, int distance, char direction)
{
 Console.WriteLine("Making a move for " + players[playerNo].Name);

 switch (direction)
{
 case 'U':
 // Moving the player up - need to decrease the value of Y
 // because the origin is the top left hand corner of the board
 players[playerNo].Y = players[playerNo].Y - distance;
 // This might take us off the top of the board, so we need to
 // wrap round
 if (players[playerNo].Y < 0)
 {
 players[playerNo].Y = players[playerNo].Y + 8;
 }
 break;

 case 'D': //down
 players[playerNo].Y = players[playerNo].Y - distance;
 // need to move down - increase Y
 if (players[playerNo].Y > 0)
 {
 players[playerNo].Y = players[playerNo].Y - 8;
 }
 break;
 case 'L':
 players[playerNo].Y = players[playerNo].Y - distance;
 break;

 case 'R':
 break;
 }